baseAction中:
public void write2JsonArray(List<?> list, String[] excludes) throws IOException {
// JsonConfig: 配置转换的json数据中不需要的属性
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(excludes);
// 将转化为json数组
String json = JSONArray.fromObject(list, jsonConfig).toString();
ServletActionContext.getResponse().setContentType("test/json;charset=UTF-8");
ServletActionContext.getResponse().getWriter().print(json);
}
------------------------------------------------------------
动作类中:
List<Area> list = areaService.findAll();
String[] excludes = { "subareas" };
this.write2JsonArray(list, excludes);
时间: 2024-10-08 17:32:41