Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of List paging in java

Shulou Source: shulou.com Published: 2022-06-02 08:51:30 10月25日 Update

This article introduces the relevant knowledge of "what are the methods of List pagination in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. According to the paging parameters of input parameters, sql query paging Criteria criteria = new Criteria (); / / convert dataAuto to factoryId brandId seriesId and other query conditions String dataAuth = ""; TypeCaseHelper.dataAuto (criteria, dataAuth); / / set paging information ExtPager pager = new ExtPager (); Integer startTure = start * pageSize; criteria.setMysqlPageSize (pageSize); criteria.setMysqlStart (startTure) / / sorting information if (StringUtils.isNotBlank (pager.getDir ()) & & StringUtils.isNotBlank (pager.getSort () {criteria.setOrderByClause (pager.getSort () + "+ pager.getDir ());} List listDistinct = getVhlAlarmStatusMgtEntities (vin, faultStatus, confirmStatus, startDateTime, endDateTime, sdf, sdfm, carTypeList, criteria)

Corresponding paging sql

Select from status_mgt and car_type in # {item} and alarm_time > = str_to_date (# {condition.startDateTime,jdbcType=VARCHAR},'% Y-%m-%d% HRV% iRV% S') and str_to_date (# {condition.endDateTime,jdbcType=VARCHAR} '% Y-%m-%d% HRV% iRV% S') > = alarm_time and logic_flag = 1 order by alarm_time desc limit # {mysqlStart}, # {mysqlPageSize} 2. Paging all list according to paging parameters Criteria criteria1 = new Criteria (); List listDistinctForCout = getVhlAlarmStatusMgtEntities (vin, faultStatus, confirmStatus, startDateTime, endDateTime, sdf, sdfm, carTypeList, criteria1); Integer count = listDistinctForCout.size (); / / Total number of records Integer pageCount; / / if (count% pageSize = 0) {pageCount = count / pageSize;} else {pageCount = count / pageSize + 1 } int fromIndex; / / start index int toIndex; / / end index 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 pageList = listDistinctForCout.subList (fromIndex, toIndex); 3.PageHelper pagination / / Open paging PageHelper.startPage (Integer.parseInt (pageNum), Integer.parseInt (pageSize)); PageInfo pageInfo = new PageInfo (datalist); HashMap map= new HashMap () Map.put ("datalist", datalist); map.put ("total", pageInfo.getTotal ()); map.put ("size", pageInfo.getPageSize ()); map.put ("page", pageInfo.getPageNum ()); "what are the methods of List pagination in java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Method information content parameters more knowledge index query practicality achievement next dilemma actual total situation article condition case editor website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Huawei Linux Docker