標籤: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