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;
https://www.leftso.com/article/487.html