js converts RFC3339 time format to normal format

Time conversion in the background

  • The design of the time field of the database table is DateTime type, but when it is generated by reverse engineering, it is Date type, so the type of the database and the type of the entity class are inconsistent, resulting in the detected value, but the attribute value corresponding to the entity class is null .
  • And this problem is taken into account in the reverse generation, which is achieved through the type of timestamp.
<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>

Realize by defining jdbcType = "TIMESTAMP"

Be sure to add resultMap="BaseResultMap" in the return type of the method

<select id="getUserList" resultMap="BaseResultMap">
     select * from login_user
</select>

The front desk converts RFC3339 time format to normal format

//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;
}

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_37469055/article/details/96046481