Beispiel #1
0
  protected Query setPageParameterToQuery(Query q, Page<T> page) {
    AssertUtils.isTrue(page.getPageSize() > 0, "Page Size must larger than zero");

    q.setFirstResult(page.getOffset());
    q.setMaxResults(page.getPageSize());

    return q;
  }
Beispiel #2
0
  protected Criteria setPageParameterToCriteria(Criteria c, Page<T> page) {
    AssertUtils.isTrue(page.getPageSize() > 0, "Page Size must larger than zero");

    c.setFirstResult(page.getOffset());
    c.setMaxResults(page.getPageSize());

    if (page.isOrderBySetted()) {
      String[] orderByArray = StringUtils.split(page.getOrderBy(), ',');
      String[] orderArray = StringUtils.split(page.getOrder(), ',');

      AssertUtils.isTrue(orderByArray.length == orderArray.length, "分页多重排序参数中,排序字段与排序方向的个数不相等");

      for (int i = 0; i < orderByArray.length; ++i) {
        if ("asc".equals(orderArray[i])) c.addOrder(Order.asc(orderByArray[i]));
        else {
          c.addOrder(Order.desc(orderByArray[i]));
        }
      }
    }
    return c;
  }
Beispiel #3
0
  public Page<T> findPage(Page<T> page, Criterion[] criterions) {
    AssertUtils.notNull(page, "page不能为空");

    Criteria c = createCriteria(criterions);

    long totalCount = countCriteriaResult(c);
    page.setTotalItems(totalCount);

    setPageParameterToCriteria(c, page);

    List result = c.list();
    page.setResult(result);
    return page;
  }
Beispiel #4
0
  public Page<T> findPage(Page<T> page, String hql, Map<String, ?> values) {
    AssertUtils.notNull(page, "page不能为空");

    Query q = createQuery(hql, values);

    long totalCount = countHqlResult(hql, values);
    page.setTotalItems(totalCount);

    setPageParameterToQuery(q, page);

    List result = q.list();
    page.setResult(result);
    return page;
  }