如果你的数据库设计种使用了timpstamp字段,想用ORM框架Mybatis封装时,实体类使用java.sqlTimpstamp 那么恭喜你。你使用Timptamp对象传入的值包含毫秒值,这个结果将会直接影响到你存储Mysql的结果!看似插入成功了,实际Mysql存储的时间可不是你指定的时间。
Timpstamp 输出示例:
@Test
void contextLoads() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
System.out.println(timestamp.toString()); // 2022-01-11 10:53:12.344
}
所以实体类也不要用Date和Timpstamp了,直接使用String!
/**
* 乐透开始时间
*/
@ApiModelProperty(value = "乐透开始时间")
private String lotteryStart;
Mybatis的xml相关字段直接写:jdbcType=TIMESTAMP
<if test="lotteryStart != null">
#{lotteryStart,jdbcType=TIMESTAMP},
</if>
这样你在对字段赋值的时候使用
String startdate = new DateTime().toString();
//DateTime是Hutool包下的:结果是 精确到秒的!
输出:2020-01-02 03:04:05
完成!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有