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”
时间: 2024-10-10 04:23:19