mysql 数据库datetime 类型,转换为DO里面的long类型后,只剩下年了,没有了月和日

解决方法也简单:

自定义个一个 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();
    }
}
相关推荐
雪碧聊技术13 小时前
组合查询(union)
数据库·sql
杨云龙UP13 小时前
ODA运维实战:Oracle 19c YJXT PDB表空间在线扩容全过程_20260503
linux·运维·服务器·数据库·oracle
BENA ceic13 小时前
Spring 的三种注入方式?
java·数据库·spring
2401_8955213413 小时前
MySQL中的count函数
数据库·mysql
雪碧聊技术13 小时前
IO流-07:缓冲流
数据库
.小小陈.13 小时前
MySQL 入门到实战:从基础概念到核心存储引擎
数据库·mysql
IT邦德13 小时前
Oracle 26ai 首发季度补丁 23.26.2.0.0 来了!单机版升级
数据库·oracle
yoyo_zzm13 小时前
Laravel10.x新特性全解析
数据库·mysql·架构
许彰午14 小时前
CacheSQL(五):桥接篇
java·数据库·缓存·系统架构
七夜zippoe14 小时前
# DolphinDB分区策略:RANGE分区详解
数据库·策略·分区·range·dolphindb