示例#1
0
  // @RequestMapping(value = "queryAllRoleList", method = { RequestMethod.POST })
  public String queryAllRoleList(HttpServletRequest request, HttpServletResponse response) {
    int page = Integer.parseInt(request.getParameter("page")); // 当前页数
    int rows = Integer.parseInt(request.getParameter("rows")); // 每页多少行
    int startNum = page * rows - rows; // 分页查询开始位置
    String roleJsonStr = "";
    Datagrid datagrid = new Datagrid();
    int roleTotalCount = roleService.queryRoleTotalCount(); // 统计角色数量
    List<Role> roleList = roleService.quryAllRoleList(startNum, rows); // 查询角色列表
    datagrid.setRows(roleList);
    datagrid.setTotal(roleTotalCount);
    try {
      // 将查询的角色集合list转换成json格式字符串
      roleJsonStr = Json.toJson(datagrid); // JsonUtils.objectToJackson(datagrid, Datagrid.class);
      PrintWriter out = response.getWriter();
      out.print(roleJsonStr);
      out.flush();
      out.close();
      request.setAttribute("roleJsonStr", roleJsonStr);
    } catch (Exception e) {
      log.error("处理json数据报错:" + e.getStackTrace());
    }
    log.info(roleJsonStr);

    return null;
  }
示例#2
0
  // @RequestMapping(value="getRoleByRoleName",method={RequestMethod.POST})
  public String getRoleByRoleName(
      HttpServletRequest request, HttpServletResponse response, String roleName) {
    int page = Integer.parseInt(request.getParameter("page")); // 当前页数
    int rows = Integer.parseInt(request.getParameter("rows")); // 每页多少行
    int startNum = page * rows - rows; // 分页查询开始位置

    List<Role> roles = roleService.getRoleByRoleName(roleName, startNum, rows);
    int rolesTotalCountByRoleName = roleService.getRolesTotalCountByRoleName(roleName);
    Datagrid datagrid = new Datagrid();
    datagrid.setRows(roles);
    datagrid.setTotal(rolesTotalCountByRoleName);
    String rolesJsonStr = "";
    try {
      rolesJsonStr =
          Json.toJson(
              datagrid); // JsonUtils.objectToJackson(datagrid, Datagrid.class);// 将对象转换成json字符串
      PrintWriter out = response.getWriter();
      out.print(rolesJsonStr);
      out.flush();
      out.close();
    } catch (Exception e) {
      log.error("处理json数据报错:" + e.getStackTrace());
    }
    return null;
  }