Example #1
0
  public static Page pageQuery(
      SqlSessionTemplate sqlSessionTemplate,
      String statementName,
      String countStatementName,
      PageRequest pageRequest) {

    Number totalCount = (Number) sqlSessionTemplate.selectOne(countStatementName, pageRequest);
    if (totalCount == null || totalCount.longValue() <= 0) {
      return new Page(pageRequest, 0);
    }

    Page page = new Page(pageRequest, totalCount.intValue());

    // 其它分页参数,用于不喜欢或是因为兼容性而不使用方言(Dialect)的分页用户使用.
    // 与getSqlMapClientTemplate().queryForList(statementName, parameterObject)配合使用
    Map filters = new HashMap();
    filters.put("offset", page.getFirstResult());
    filters.put("pageSize", page.getPageSize());
    filters.put("lastRows", page.getFirstResult() + page.getPageSize());
    filters.put("sortColumns", pageRequest.getSortColumns());

    Map parameterObject = PropertyUtils.describe(pageRequest);
    filters.putAll(parameterObject);

    List list =
        sqlSessionTemplate.selectList(
            statementName, filters, page.getFirstResult(), page.getPageSize());
    page.setResult(list);
    return page;
  }
Example #2
0
  protected Page pageQuery(String statementName, PageRequest pageRequest) {

    Number totalCount =
        (Number)
            this.getSqlMapClientTemplate()
                .queryForObject(getCountQuery(statementName), pageRequest.getFilters());
    if (totalCount == null || totalCount.longValue() <= 0) {
      return new Page(pageRequest, 0);
    }
    Page page = new Page(pageRequest, totalCount.intValue());

    // 其它分页参数,用于不喜欢或是因为兼容性而不使用方言(Dialect)的分页用户使用.
    // 与getSqlMapClientTemplate().queryForList(statementName, parameterObject)配合使用
    Map otherFilters = new HashMap();
    otherFilters.put("offset", page.getFirstResult());
    otherFilters.put("pageSize", page.getPageSize());
    otherFilters.put("lastRows", page.getFirstResult() + page.getPageSize());
    otherFilters.put("sortColumns", pageRequest.getSortColumns());

    // 混合两个filters为一个filters,MapAndObject.get()方法将在两个对象取值,Map如果取值为null,则再在Bean中取值
    Map parameterObject = new MapAndObject(otherFilters, pageRequest.getFilters());
    List list =
        getSqlMapClientTemplate()
            .queryForList(
                statementName, parameterObject, page.getFirstResult(), page.getPageSize());
    page.setResult(list);
    return page;
  }