Spring Boot 2.0 @JsonFormat注解失效解决

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(1917)   2023-03-28 11:29:14

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

相关阅读

Spring Boot 2.0 @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") 注解格式化日期失效原因及解决。
Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。
spring boot 2.0 security 5.0 整合,实现自定义表单登录。spring boot 2.0框架使用。
Spring Boot 2.0 有哪些新特性_Spring Boot 2.0新功能,在本文中,我们将探讨为Spring Boot 2.0计划的一些更改和功能。我们还会描述这些变化如何帮助我们提高...
Spring Boot 2.0,Spring框架的Spring Boot 中的Spring Boot Actuator变化讲解。并且了解如何在Spring Boot 2.0中使用Actuator...
Spring Boot 1.x升级到Spring Boot 2.0迁移指南
Spring Boot 2.0 绑定properties属性资源文件 Spring Boot 2.0 读取properties配置文件值 Spring Boot 2.0获取properties配...
Spring Boot 2.0 支持的Apache Camel 版本发布了_Apache Camel 2.22发布支持Spring Boot 2.0