解决方法也简单:
自定义个一个 Date2LongTypeHandler
<resultMap id="BeanResult" type="XXXX.XXXXDO">
<result column="gmt_create" property="gmtCreate" jdbcType="DATE" javaType="java.lang.Long"
typeHandler="XXXX.Date2LongTypeHandler"/>
<result column="gmt_modified" property="gmtModified" jdbcType="DATE" javaType="java.lang.Long"
typeHandler="XXXXX.Date2LongTypeHandler"/>
</resultMap>
Date2LongTypeHandler类实现如下:
java
public class Date2LongTypeHandler extends BaseTypeHandler<Long> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Long date, JdbcType jdbcType) throws SQLException {
ps.setDate(i, new java.sql.Date(date));
}
@Override
public Long getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
return toLong(resultSet.getDate(columnName));
}
@Override
public Long getNullableResult(ResultSet resultSet, int i) throws SQLException {
return toLong(resultSet.getDate(i));
}
@Override
public Long getNullableResult(CallableStatement cs, int i) throws SQLException {
return toLong(cs.getDate(i));
}
private Long toLong(Date time) {
if (time == null) {
return null;
}
return time.getTime();
}
}