java中List分頁(yè)的幾種方法介紹
1.根據(jù)入?yún)Х猪?yè)參數(shù)進(jìn)行sql查詢分頁(yè)
Criteria criteria = new Criteria(); //將dataAuto轉(zhuǎn)成 factoryId brandId seriesId 等查詢條件 String dataAuth = ""; TypeCaseHelper.dataAuto(criteria, dataAuth); // 設(shè)置分頁(yè)信息 ExtPager pager = new ExtPager(); Integer startTure = start * pageSize; criteria.setMysqlPageSize(pageSize); criteria.setMysqlStart(startTure); // 排序信息 if (StringUtils.isNotBlank(pager.getDir()) && StringUtils.isNotBlank(pager.getSort())) { criteria.setOrderByClause(pager.getSort() + " " + pager.getDir()); } List<VhlAlarmStatusMgtEntity> listDistinct = getVhlAlarmStatusMgtEntities(vin, faultStatus, confirmStatus, startDateTime, endDateTime, sdf, sdfm, carTypeList, criteria);
對(duì)應(yīng)的分頁(yè)sql
<select id="selectByExample" parameterType="Criteria" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from status_mgt <where> <if test="condition.carTypeList != null and condition.carTypeList.size() > 0" > and car_type in <foreach collection="condition.carTypeList" item="item" open="(" separator="," close=")"> #{item} </foreach> </if> <if test="condition.startDateTime != null and condition.startDateTime!=''"> and alarm_time >= str_to_date(#{condition.startDateTime,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%S') </if> <if test="condition.endDateTime != null and condition.endDateTime!=''"> and str_to_date(#{condition.endDateTime,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%S') >= alarm_time </if> and logic_flag = 1 </where> order by alarm_time desc <if test="mysqlStart != null and mysqlPageSize != null"> limit #{mysqlStart}, #{mysqlPageSize} </if> </select>
2.對(duì)所有l(wèi)ist根據(jù)分頁(yè)參數(shù)分頁(yè)
Criteria criteria1 = new Criteria(); List<VhlAlarmStatusMgtEntity> listDistinctForCout = getVhlAlarmStatusMgtEntities(vin, faultStatus, confirmStatus, startDateTime, endDateTime, sdf, sdfm, carTypeList, criteria1); Integer count = listDistinctForCout.size(); // 記錄總數(shù) Integer pageCount; // 頁(yè)數(shù) if (count % pageSize == 0) { pageCount = count / pageSize; } else { pageCount = count / pageSize + 1; } int fromIndex; // 開(kāi)始索引 int toIndex; // 結(jié)束索引 if (!pageCount.equals(start+1)) { fromIndex = start * pageSize; toIndex = fromIndex + pageSize; if(toIndex > count){ fromIndex = (start-1) * pageSize; toIndex = count; } } else { fromIndex = start * pageSize; toIndex = count; } List<VhlAlarmStatusMgtEntity> pageList = listDistinctForCout.subList(fromIndex, toIndex);
3.PageHelper分頁(yè)
//開(kāi)啟分頁(yè) PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize)); PageInfo<Map<String, String>> pageInfo = new PageInfo(datalist); HashMap<String, Object> map= new HashMap<>(); map.put("datalist", datalist); map.put("total", pageInfo.getTotal()); map.put("size", pageInfo.getPageSize()); map.put("page", pageInfo.getPageNum());
到此這篇關(guān)于java中List分頁(yè)的幾種方法介紹的文章就介紹到這了,更多相關(guān)java List分頁(yè)方法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis中SqlSession接口中selectList方法詳解
這篇文章主要給大家介紹了關(guān)于Mybatis中SqlSession接口中selectList方法的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-03-03Struts2學(xué)習(xí)筆記(6)-簡(jiǎn)單的數(shù)據(jù)校驗(yàn)
這篇文章主要介紹Struts2中的數(shù)據(jù)校驗(yàn),通過(guò)一個(gè)簡(jiǎn)單的例子來(lái)說(shuō)明,希望能給大家做一個(gè)參考。2016-06-06Java實(shí)現(xiàn)求子數(shù)組和的最大值算法示例
這篇文章主要介紹了Java實(shí)現(xiàn)求子數(shù)組和的最大值算法,涉及Java數(shù)組遍歷、判斷、運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2018-02-02Java管道流實(shí)現(xiàn)線程間通信過(guò)程解析
這篇文章主要介紹了Java管道流實(shí)現(xiàn)線程間通信過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03