集合和JSON裝換
阿新 • • 發佈:2018-11-02
//使用json-lib將PageBean物件轉為json,通過輸出流寫回頁面中
//JSONObject---將單一物件轉為json
//JSONArray----將陣列或者集合物件轉為json
注:需要將引用型別的去掉,否則會報錯,迴圈引用
public String findAll() throws IOException{ List<BcStaff> list=staffService.findAll(); JsonConfig config = new JsonConfig(); config.setExcludes(new String[]{"qpWorkbills","qpNoticebills","qpNoticebills_1","bcDecidedzones","qpWorkbills_1","bcDecidedzones_1"}); String listString = JSONArray.fromObject(list,config).toString(); ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); ServletActionContext.getResponse().getWriter().print(listString); return NONE; }