java日期属性json格式化

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;

public class User {
	
	private Long id;
	private String username;
	// 日期类型输出到页面格式
	@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")  
	// 页面字符串格式化为日期
	@DateTimeFormat(pattern="yyyy-MM-dd") 
	// 代码中转JSON格式字符串
	@JSONField(format="yyyyMMdd")
	private Date birthday;
	private Integer status;
	
	//getter setter 略
	
}

猜你喜欢

转载自hbxflihua.iteye.com/blog/2405227