Spring Boot 2.0 @JsonFormat注解失效解决
Spring Boot 2.0 @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") 注解格式化日期失效原因及解决。
项目为Spring Boot 2.0+ mybaties整合使用了mybaties的分页组件pagehelper
Bean:
public class BeanObject{
....
private Date createTime;
....
} VO:
public class BeanObjectVO{
....
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
private Date createTime;
....
} 业务代码片段:
....
com.github.pagehelper.PageInfo<BeanObject> pageInfo=getData(xxx);//获取数据
com.github.pagehelper.PageInfo<BeanObjectVO> pageData=new PageInfo<>();
org.springframework.beans.BeanUtils.copyProperties(pageInfo,pageData);
return pageData;
} 解决问题:
com.github.pagehelper.PageInfo<BeanObject> pageInfo=getData(xxx);//获取数据
List<BeanObject> list=pageInfo.getList();
List<BeanObjectVO> vos=new ArrayList<>();
if(list!=null){
BeanObjectVO vo;
for(BeanObject o:list){
vo=new BeanObjectVO();
org.springframework.beans.BeanUtils.copyProperties(o,vo);
vos.add(vo);
}
}
org.springframework.beans.BeanUtils.copyProperties(pageInfo,pageData);
pageData.setList(vos);
return pageData;
版权所有 © 【代码谷】 欢迎非商用转载,转载请按下面格式注明出处,商业转载请联系授权,违者必究。(提示:点击下方内容复制出处)
源文:《Spring Boot 2.0 @JsonFormat注解失效解决》,链接:https://www.daimagu.com/article/487.html,来源:【代码谷】
评论