集合和JSON装换

     //使用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;
	}

猜你喜欢

转载自blog.csdn.net/qq_34117624/article/details/83623410