mybatis 插入数据库字段类型为timestamp的时间,精确到毫秒

 前提:时间在后台插入,不是从前端传入。

 

步骤:

①数据库类型设置为 timestamp(只有这种类型能保存到毫秒)

②后台实体类设置 类型为String

③Service实现层

 //格式化时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String  nowDate  =  sdf.format(new Date());

④Mapper层  jdbcType类型设置为 TIMESTAMP

posted @ 2022-09-16 14:54  小牛同学丶  阅读(472)  评论(0编辑  收藏  举报