标签:.text nts reflect util nconf 请求 .json 问题 roc
import java.text.SimpleDateFormat; import net.sf.json.JsonConfig; import net.sf.json.processors.JsonValueProcessor; public class DateJsonValueProcessor implements JsonValueProcessor{ private String format; public DateJsonValueProcessor(String format) { this.format = format; } public Object processArrayValue(Object value, JsonConfig jsonConfig) { return null; } public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) { if (value == null) { return ""; } if (value instanceof java.sql.Timestamp) { String str = new SimpleDateFormat(format) .format((java.sql.Timestamp) value); return str; } if (value instanceof java.util.Date) { String str = new SimpleDateFormat(format) .format((java.util.Date) value); return str; } return value.toString(); } }
JsonConfig cfg = new JsonConfig();
cfg.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
JSONArray json = JSONArray.fromObject(users, cfg);
@RequestMapping("/getAllJsonUser") public void getAllJsonUser(HttpServletResponse response){ List<User> users = userService.listAll(); System.out.println(users); JsonConfig cfg = new JsonConfig(); cfg.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); JSONArray json = JSONArray.fromObject(users, cfg); JsonUtils.ajaxJson(json.toString(), response); }
ok,问题解决
标签:.text nts reflect util nconf 请求 .json 问题 roc
原文地址:http://www.cnblogs.com/javafucker/p/7509425.html