예제 #1
0
  @Result(success = "/WEB-INF/pages/group/filter.jsp")
  @Override
  public String filter(HttpServletRequest req, HttpServletResponse resp) {
    StringBuilder filter = new StringBuilder();
    String groupname = param(req, "groupname", "");
    // 默认排序
    String by = param(req, "by", "groupname");
    String order = param(req, "order", "desc");
    Group model = new Group();
    model.setGroupname(groupname);
    if (StringUtils.isNotBlank(groupname)) {
      filter.append(" where ");
      filter.append(" groupname like '%" + groupname + "%'");
    }
    filter.append(" order by ");
    filter.append(by);
    filter.append(" ");
    filter.append(order);
    // 前台分页
    int p = Configuration.DEFAULT_CURRENT_PAGE;
    int countPerPage = Configuration.DEFAULT_COUNT_PER_PAGE;
    try {
      p = param(req, "page", Configuration.DEFAULT_CURRENT_PAGE);
      if (p < 1) p = Configuration.DEFAULT_CURRENT_PAGE;
    } catch (NumberFormatException e) {
      p = Configuration.DEFAULT_CURRENT_PAGE;
    }
    try {
      countPerPage = param(req, "countPerPage", Configuration.DEFAULT_COUNT_PER_PAGE);
    } catch (NumberFormatException e) {
      countPerPage = Configuration.DEFAULT_COUNT_PER_PAGE;
    }
    int currentPage = p;
    int totalCount = model.totalCount(filter.toString());
    Pager pager = new Pager(currentPage, countPerPage, totalCount);
    // 针对可能的原访问页数大于实际总页数,此处重置下
    if (currentPage > pager.getTotalPage()) currentPage = p = pager.getTotalPage();
    // 读取部分数据
    @SuppressWarnings("unchecked")
    List<Group> list =
        (List<Group>) model.filterByPage(filter.toString(), p, pager.getCountPerPage());

    setAttr(req, CURRENT_PAGE_KEY, currentPage);
    setAttr(req, CURRENT_COUNT_PER_PAGE_KEY, countPerPage);
    setAttr(req, PAGER_KEY, pager);
    setAttr(req, MAX_PAGERSHOW_LENGTH_KEY, DEFAULT_MAX_PAGERSHOW_LENGTH);
    setAttr(req, DATA_LIST, list);
    // 查询值
    setAttr(req, GROUPNAME, groupname);
    setAttr(req, BY, by);
    setAttr(req, ORDER, order);

    // 批量删除传来的消息
    String tip = (String) getAttr(req, TIP_NAME_KEY);
    setAttr(req, TIP_NAME_KEY, tip);

    setAttr(req, MODEL, model);

    return SUCCESS;
  }
예제 #2
0
  @Result(success = "/WEB-INF/pages/user/filter.jsp", fail = "/WEB-INF/pages/user/filter.jsp")
  @Override
  public String filter(HttpServletRequest req, HttpServletResponse resp) {
    StringBuilder filter = new StringBuilder();
    String username = param(req, "username", "");
    // 默认排序
    String by = param(req, "by", "username");
    String order = param(req, "order", "desc");
    User model = new User();
    model.setUsername(username);
    if (StringUtils.isNotBlank(username)) {
      filter.append(" where ");
      filter.append(" username like '%" + username + "%'");
    }
    filter.append(" order by ");
    filter.append(by);
    filter.append(" ");
    filter.append(order);
    // 前台分页
    int p = Configuration.DEFAULT_CURRENT_PAGE;
    int countPerPage = Configuration.DEFAULT_COUNT_PER_PAGE;
    try {
      p = param(req, "page", Configuration.DEFAULT_CURRENT_PAGE);
      if (p < 1) p = Configuration.DEFAULT_CURRENT_PAGE;
    } catch (NumberFormatException e) {
      p = Configuration.DEFAULT_CURRENT_PAGE;
    }
    try {
      countPerPage = param(req, "countPerPage", Configuration.DEFAULT_COUNT_PER_PAGE);
    } catch (NumberFormatException e) {
      countPerPage = Configuration.DEFAULT_COUNT_PER_PAGE;
    }
    int currentPage = p;
    int totalCount = model.totalCount(filter.toString());
    Pager pager = new Pager(currentPage, countPerPage, totalCount);
    // 针对可能的原访问页数大于实际总页数,此处重置下
    if (currentPage > pager.getTotalPage()) currentPage = p = pager.getTotalPage();
    // 读取部分数据
    @SuppressWarnings("unchecked")
    List<User> list =
        (List<User>) model.filterByPage(filter.toString(), p, pager.getCountPerPage());
    // 过滤管理员
    List<User> listFilter = new ArrayList<User>();
    String sessionUser = ((String) req.getSession().getAttribute(LOGIN_USER_KEY)).split("&")[1];
    for (User u : list) {
      if (!u.getUsername().equals("admin")) {
        listFilter.add(u);
      }
    }
    setAttr(req, CURRENT_PAGE_KEY, currentPage);
    setAttr(req, CURRENT_COUNT_PER_PAGE_KEY, countPerPage);
    setAttr(req, PAGER_KEY, pager);
    setAttr(req, MAX_PAGERSHOW_LENGTH_KEY, DEFAULT_MAX_PAGERSHOW_LENGTH);
    if (sessionUser.equals("admin")) {
      setAttr(req, DATA_LIST, list);
    } else {
      setAttr(req, DATA_LIST, listFilter);
    }
    // 查询值
    setAttr(req, USERNAME, username);
    setAttr(req, BY, by);
    setAttr(req, ORDER, order);

    // 批量删除传来的消息
    String tip = (String) getAttr(req, TIP_NAME_KEY);
    setAttr(req, TIP_NAME_KEY, tip);

    setAttr(req, MODEL, model);

    return SUCCESS;
  }