public class CustomDateSerializer extends JsonSerializer<Date>
{
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)throws IOException, JsonProcessingException
{
SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = format.format(date);
gen.writeString(formattedDate);
}
}
package com.easyui.model;
import java.util.Date;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.springframework.format.annotation.DateTimeFormat;
import com.easyui.utils.CustomDateSerializer;
public class User {
private Integer id;
private String username;
private String password;
private String realname;
private String sex;
private Date birthday;
public int getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@JsonSerialize(using=CustomDateSerializer.class)
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}