使用之前要导入相应的jar包:
*/
public String findByTypeCode() throws IOException {
//调用业务层查询
List<BaseDict> list= baseDictService.findByTyCode(baseDict.getDict_type_code());
for (BaseDict baseDict : list) {
System.out.println(baseDict);
}
//将 list 转换为 json jsonlib fastjson
/**
* JSONConfig:转json的配置对象
* JSONArray:将数组和List转换为json
* JSONObject:将对象和Map转换为json
*/
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.setExcludes(new String[] {//去掉不想要的字段
"dict_sort","dict_enable","dict_memo"
});
JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
System.out.println(jsonArray);
//将Json数据打印到页面
ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
ServletActionContext.getResponse().getWriter().write(jsonArray.toString());//写到页面上
return NONE;
}