利用阿里的json工具还是挺方便的,直接看代码
1、先有一个实体类StudentInfoDto
package com.myapp.dto;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
public class StudentInfoDto extends Object{
private Integer studentSn;
private String studentName;
private String sex;
/**
* 序列化日期,使之按照指定格式输出,如果不指定,则会输出当前时间戳
* 比如:2017-08-02 16:50:29.929
*/
@JSONField(format="yyyy-MM-dd HH:mm:ss.SSS")
private Date birthday;
public StudentInfoDto(){
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Date getBirthday() {
return birthday;
}
public StudentInfoDto(Integer studentSn,String studentName,String sex,Date birthday){
super();
this.studentSn = studentSn;
this.studentName = studentName;
this.sex = sex;