/**
   * 查询所有的用户
   *
   * @param page
   * @param pfList 查询条件
   * @return
   */
  public Page<UserInfo> findAllUsers(Page<UserInfo> page, List<PropertyFilter> pfList) {
    // 初始化hql
    StringBuffer hql = new StringBuffer("from UserInfo");
    // 设置查询条件
    String condition = QueryUtil.toSqlString(pfList, true);
    hql.append(condition);
    // 查找所有用户的总条数
    int totalCount = this.userDAO.findCountBySql(hql.toString());
    page.setTotalCount(totalCount);

    // 是否存在排序
    if (page.isOrderBySetted()) {
      hql.append(page.getOrder());
    }
    List<UserInfo> list =
        this.userDAO.findList(hql.toString(), page.getPageNo(), page.getPageSize());
    // 查出结果集
    page.setResult(list);

    return page;
  }
Exemplo n.º 2
0
  /**
   * 新闻列表
   *
   * @author wei.luo
   * @createTime 2012-4-29
   * @param request
   * @param response
   * @param model
   * @param queryDTO
   * @return
   */
  @RequestMapping(value = "/list")
  public String list(
      HttpServletRequest request, HttpServletResponse response, Model model, QueryDTO queryDTO) {

    String name = queryDTO.getKey();
    int pageNo = queryDTO.getPageNo();
    String order = queryDTO.getOrder();
    String startDate = queryDTO.getStartDate();
    String endDate = queryDTO.getEndDate();
    int pageSize = queryDTO.getPageSize();
    if (pageSize == 0) {
      pageSize = 10;
    }

    // 查询条件
    List<PropertyFilter> pfList = new ArrayList<PropertyFilter>();
    pfList.add(new PropertyFilter("title:LIKE_S", name));
    pfList.add(new PropertyFilter("createtime:GT_D", startDate));
    pfList.add(new PropertyFilter("createtime:LT_D", endDate));

    // 获取分页跳转页面
    List<Condition> fragmentList = new ArrayList<Condition>();
    fragmentList.add(new Condition("key", EncodeUtil.urlEncode(name), "匹配'" + name + "'"));
    fragmentList.add(new Condition("order", order, "排序", false));
    fragmentList.add(new Condition("startDate", startDate, "大于" + startDate));
    fragmentList.add(new Condition("endDate", endDate, "小于" + endDate));

    // 设置跳转页面
    StringBuffer forwordName = new StringBuffer(this.getRoot(request) + "/manage/news/list.do");
    String forwarCondition = PageUtil.getForwardCondition(fragmentList);
    forwordName.append(forwarCondition);

    // 获取排序跳转页面
    String orderCondition = PageUtil.getOrderCondition(fragmentList);
    model.addAttribute("order", orderCondition);

    // 获取过滤查询集合
    List<Condition> filterList = PageUtil.getFilterConditions(fragmentList);
    model.addAttribute("filterList", filterList);

    // 初始化page属性值--默认id排序
    Page<News> page = new Page<News>(pageSize);
    if (null == order) {
      page.setOrder("id:asc");
    } else {
      page.setOrder(order);
    }
    page.setPageNo(pageNo);
    String hql = "from News";
    page = this.findAll(newsService, page, pfList, hql);
    model.addAttribute("newsList", page.getResult());

    // 生成分页标签
    page.setForwordName(forwordName.toString());
    String tag = PageUtil.getTag(page);
    model.addAttribute("tag", tag);
    // 索引号
    model.addAttribute("index", page.getFirst());

    // 设置页面搜索初始值
    model.addAttribute("key", name);
    model.addAttribute("startDate", startDate);
    model.addAttribute("endDate", endDate);

    String currentPage = request.getRequestURI().toString() + forwarCondition + page.getPageNo();
    request.getSession().setAttribute("currentPage", currentPage);
    return "manage/news/list";
  }