您好,登錄后才能下訂單哦!
本篇內容介紹了“java中List分頁的方法有哪些”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
Criteria criteria = new Criteria(); //將dataAuto轉成 factoryId brandId seriesId 等查詢條件 String dataAuth = ""; TypeCaseHelper.dataAuto(criteria, dataAuth); // 設置分頁信息 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);
對應的分頁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>
Criteria criteria1 = new Criteria(); List<VhlAlarmStatusMgtEntity> listDistinctForCout = getVhlAlarmStatusMgtEntities(vin, faultStatus, confirmStatus, startDateTime, endDateTime, sdf, sdfm, carTypeList, criteria1); Integer count = listDistinctForCout.size(); // 記錄總數 Integer pageCount; // 頁數 if (count % pageSize == 0) { pageCount = count / pageSize; } else { pageCount = count / pageSize + 1; } int fromIndex; // 開始索引 int toIndex; // 結束索引 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);
//開啟分頁 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());
“java中List分頁的方法有哪些”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。