解决方法也简单:
自定义个一个 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类实现如下:
public class Date2LongTypeHandler extends BaseTypeHandler<Long> {@Overridepublic void setNonNullParameter(PreparedStatement ps, int i, Long date, JdbcType jdbcType) throws SQLException {ps.setDate(i, new java.sql.Date(date));}@Overridepublic Long getNullableResult(ResultSet resultSet, String columnName) throws SQLException {return toLong(resultSet.getDate(columnName));}@Overridepublic Long getNullableResult(ResultSet resultSet, int i) throws SQLException {return toLong(resultSet.getDate(i));}@Overridepublic 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();}
}