@RequestMapping("/getAllRoles") public void getAllRoles(HttpServletResponse response) { response.setCharacterEncoding("utf-8"); List<Role> roles = roleService.findAll(); String json = JSON.toJSONString(roles); try { response.getWriter().print(json); } catch (IOException e) { e.printStackTrace(); } }
/** * @Description: TODO * * @param @param user * @param @param response * @param @param page 第几页 * @param @param rows 一页显示多少条 * @return void * @throws * @author work * @date 2016年4月11日 上午12:58:32 */ @RequestMapping("/getUserList") public void getUserList( @ModelAttribute User user, String type, HttpServletResponse response, int page, int rows) { response.setCharacterEncoding("utf-8"); if ("1".equals(type)) { user.setRole_id("2"); } else if ("2".equals(type)) { int id = user.getId(); if (id != 0) { User u = userService.get(id); String province = u.getProvince(); if (province != null) { user.setProvince(province); } } user.setRole_id("3"); } else { user.setRole_id("4"); } Page<User> users = userService.findByParams(user, page, rows); for (User u : users.getRows()) { Date date = u.getLogin_date(); String parseDate = ""; if (date != null) { SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); parseDate = sm.format(date); u.setParseDate(parseDate); } String role_id = u.getRole_id(); String role_name = ""; if (role_id != null) { role_name = roleService.get(Integer.parseInt(role_id)).getRole_name(); } u.setRole_name(role_name); } String json = JSON.toJSONString(users); System.out.println(json); try { response.getWriter().print(json); } catch (IOException e) { e.printStackTrace(); } }