JsonConfig 作用,去除java转json的时候去掉指定属性
String id = request.getParameter("id");
ProjectItem projectItem=projectItemService.findById(id);try {
response.setContentType("text/plain;charset=GBK");
PrintWriter out = response.getWriter();
JsonConfig jsonConfig = new JsonConfig(); //建立配置文件
jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略
jsonConfig.setExcludes(new String[]{"sample"}); //sample是projectitem的一个属性
// 设置javabean中日期转换时的格式
// jsonConfig.registerJsonValueProcessor(Date.class,
// new JsonDateValueProcessor("yyyy-MM-dd"));
JSONObject json=JSONObject.fromObject(projectItem,jsonConfig);
out.print(json);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}