1、先看下pojo类
public class User {
private String userId;
private String userName;
private String userPass;
private String sex;
private Date birth;
private Date inTime;
private Date outTime;
}
2、再看下struts2的action类
private List<User> users;
private int totalCount;
3、如果用struts2 的json-plugin功能的话,前台解析如下:
var record = new Ext.data.Record.create([ {name : "userId",type : "string"}, {name : "userName",type : "string"}, {name : "userPass",type : "string"}, {name : "sex",type : "string"}, {name : "birth",type : 'date',dateFormat : 'Y-m-d'}, {name : "inTime",type : 'date',dateFormat : 'Y-m-d'}, {name : "outTime",type : 'date',dateFormat : 'Y-m-d'} ]);
这样是得不到date类型的那几列数据的, 因为对于birth、inTime、outTime这3个的返回类型的格式不是Ext所需要的“Y-m-d”类型,因此需要对Date类型稍微处理下,
在User类中Date类型的get方法前面加上注解@JSON(format="yyyy-MM-dd") 即可。
@JSON(format="yyyy-MM-dd")
public Date getBirth() {
return birth;
}
@JSON(format="yyyy-MM-dd")
public Date getInTime() {
return inTime;
}
@JSON(format="yyyy-MM-dd")
public Date getOutTime() {
return outTime;
}