前提:时间在后台插入,不是从前端传入。
步骤:
①数据库类型设置为 timestamp(只有这种类型能保存到毫秒)
②后台实体类设置 类型为String
③Service实现层
//格式化时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowDate = sdf.format(new Date());
④Mapper层 jdbcType类型设置为 TIMESTAMP