@SuppressWarnings("unchecked")
public static Page pageQuery(SqlMapClientTemplate sqlMapClientTemplate,String statementName,String countStatementName, PageRequest pageRequest) {
Number totalCount = (Number) sqlMapClientTemplate.queryForObject(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 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);
List list = sqlMapClientTemplate.queryForList(statementName, parameterObject,page.getFirstResult(),page.getPageSize());
page.setResult(list);
return page;
}