后台的时间转换
- 数据库表对时间字段的设计为DateTime类型,但是在通过逆向生成的时候为Date类型,因此导致数据库的类型和实体类的类型不一致,导致查出来的值有,但是实体类对应的属性值为null。
- 而这个问题在逆向生成的时候考虑到了,就是通过时间戳的类型进行实现。
<resultMap id="BaseResultMap" type="com.github.springbootmiaosha.entity.User" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="password" property="password" jdbcType="VARCHAR" />
<result column="salt" property="salt" jdbcType="VARCHAR" />
<result column="last_login_time" property="lastLoginTime" jdbcType="TIMESTAMP" />
<result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
</resultMap>
通过定义jdbcType = "TIMESTAMP"进行实现
在方法中的返回类型中一定要添加resultMap=“BaseResultMap”
<select id="getUserList" resultMap="BaseResultMap">
select * from login_user
</select>
前台将RFC3339时间格式转换为正常格式
//date类型转String类型
function dateToString(date){
var date = new Date(date).toJSON();
var newDate=new Date(+new Date(date)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
return newDate;
}