日期:2014-05-16  浏览次数:20524 次

数据库操作基类设计3
    public int queryTotalCount(T criteria)
    {
        String statementName = entitySimpleClassName + ".queryCount";
        Integer totalCount = (Integer)getSqlMapClientTemplate().queryForObject(statementName, criteria);
        return totalCount;
    }
    public List<T> queryByCriteria(String statementName, Map<String, Object> criteria)
    {
        List<T> entities = getSqlMapClientTemplate().queryForList(statementName, criteria);
        return entities;
    }
    public PaginationSupport<T> queryPagingEntities(String statementName, Map<String, Object> criteria, int pageNo,
        int countPerPage)
    {  
        return queryForPagination(criteria, pageNo, countPerPage, statementName);
    }
    private PaginationSupport<T> queryForPagination(Object criteria, int pageNo, int countPerPage, String statementName)
    {
        PaginationSupport<T> entites = new PaginationSupport<T>();
        entites.setCurrentPage(pageNo);
        entites.setCountPerPage(countPerPage);
        Integer totalCount = (Integer)getSqlMapClientTemplate().queryForObject(statementName + "Count", criteria);
        entites.setTotal(totalCount);
        List<T> entityList =
            getSqlMapClientTemplate().queryForList(statementName, criteria, entites.getBegin(), countPerPage);
        entites.setItems(entityList);
        return entites;
    }
}