json转化对特殊字段的处理
//获取部门id String departmentId = (String)this.getRequest().getParameter("departmentId"); //根据部门id查询用户list List<Admin> adminList = adminService.findAllListBydepartment(departmentId); try { JsonConfig jsonConfig = new JsonConfig(); //建立配置文件 jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略 jsonConfig.setExcludes(new String[]{"roles"}); //此处是亮点,只要将所需忽略字段加到数组中即可 HttpServletResponse response = this.getResponse(); response.setContentType("text/plain;charset=UTF-8"); JSONArray array = JSONArray.fromObject(adminList, jsonConfig); response.getWriter().print(array); } catch (Exception e) { e.printStackTrace(); }