网站建议:179001057@qq.com

java 分页封装的共同DAO层

技术2022-05-12  2

java 分页封装的共同DAO层。

使用到了【封装基于hibernate的数据库操作】。import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import CommonDao; public class ListQueryDaoImpl extends CommonDao{ private Logger log = Logger.getLogger(ListQueryDaoImpl.class); //日志纪录 public Object getDataList(String sqlRel, Map mapWhere, int pageGo, int cntMax, int cntPerPage){ List list_base = null; Map<String, Object> map = new HashMap<String, Object>(); int cntStart = pageGo * cntPerPage - ( cntPerPage - 1 ); int cntEnd = pageGo * cntPerPage; String sqlStart = "select tmp2.* from( select tmp1.*, rownum rn from("; String sqlEnd = ") tmp1) tmp2 where tmp2.rn >= :CNTSTART and tmp2.rn <= :CNTEND"; String sql = sqlStart + sqlRel + sqlEnd; mapWhere.put("CNTSTART", cntStart); mapWhere.put("CNTEND", cntEnd); list_base = getData(sql, mapWhere); int pageMaxInt = cntMax / cntPerPage; Double pageMaxDouble = Double.valueOf(cntMax) / Double.valueOf(cntPerPage); int pageMax = pageMaxInt; if(pageMaxDouble - pageMaxInt > 0){ pageMax = pageMaxInt + 1; } map.put("pageMax", pageMax); map.put("cntNowPage", list_base.size()); map.put("infoList", list_base); return map; } }


最新回复(0)