springboot格式化时间

使用@RestController注解,返回的java对象中若含有date类型的属性,则默认输出为TIMESTAMP时间戳格式,可以在配置文件加入下面配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

也可以在mybatis查询的时候直接使用mysql函数"DATE_FORMAT"直接格式化,如下
@Select({
        "SELECT id,title,DATE_FORMAT(create_date,'%Y-%c-%d') create_date",
        "FROM zx_news_structure",
        "WHERE is_deleted=0 and push_type=#{pushType}",
        "order by push_topping_date desc,show_date desc limit #{limitSize}"
})
@Results({
        @Result(column="id", property="id", jdbcType= JdbcType.INTEGER),
        @Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_date", property="createTime", jdbcType=JdbcType.VARCHAR),

})
List<NewsVo> getNewsList(@Param("limitSize") int limitSize, @Param("pushType") int pushType);
原文地址:https://www.cnblogs.com/AnonymouL/p/9512273.html