标签:ima orm for date format sso class value 分享
public class JsonDateValueProcessor implements JsonValueProcessor {
private String format ="yyyyMMdd";
public JsonDateValueProcessor() {
super();
}
public JsonDateValueProcessor(String format) {
super();
this.format = format;
}
@Override
public Object processArrayValue(Object paramObject,
JsonConfig paramJsonConfig) {
return process(paramObject);
}
@Override
public Object processObjectValue(String paramString, Object paramObject,
JsonConfig paramJsonConfig) {
return process(paramObject);
}
private Object process(Object value){
if(value instanceof Date){
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
return sdf.format(value);
}
return value == null ? "" : value.toString();
}
}
controller里这样写
List<T> list = service.queryFromWtxs(); //查询到要显示的实体类表
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
JSONArray jsonArray22=JSONArray.fromObject(list,jsonConfig); //实体类表转成json;时间变转换器里的时间格式
sum = list.size();
mv.addObject("list",jsonArray22); //在jsp使用“list”
时间格式的时间 转json的时候变成正常的string时间20170519
标签:ima orm for date format sso class value 分享
原文地址:http://www.cnblogs.com/xlj227/p/6876519.html