In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Mybatis paging plug-in MicroPageInterceptor
Source address:
Https://github.com/jeffreyning/mybatis-plus
Characteristics of MicroPageInterceptor
1. Support mysql and oracle paging
2. It is not necessary to write the sql of statistical count in xml.
3. Use the Rowboundaries subclass PageInfo as the carrier of the paging information and the total number of records. It is not necessary to require that the input and output parameters must inherit the special parent class like other paging plug-ins.
4. You can enter the custom sort sql string in PageInfo to improve query performance and sorting flexibility.
Configure the mybatis paging plug-in MicroPageInterceptor in spring
It is recommended to configure it in sqlSessionFactory. The dialect property of the plug-in can be configured according to whether sqlSessionFactory is oracle or mysql.
Dao interface settin
The PageInfo parameter is added to the interface, indicating that paging is required.
/ / paging query, pass the PageInfo parameter public List queryInfoByCondition (Map paramMap,PageInfo pageInfo); / / if there is no paging, you do not need to pass the PageInfo parameter public List queryInfoByCondition (Map paramMap)
PageInfo structure
PageInfo inherits RowBounds and can be transparently transferred to Mybatis without affecting normal parameters.
PageNo, page count starts from 1
PageRows, number of messages per page
OrderStr, custom sorting sql (optional)
Total, which returns the total number of records (return value)
Public class PageInfo extends RowBounds {public PageInfo (int pageNo,int pageRows) {super (pageNo, pageRows);} public PageInfo (int offset,int limit, StringorderStr) {super (offset, limit); this.orderStr=orderStr;} private Longtotal = 0l; public Long getTotal () {returntotal;} public void setTotal (Longtotal) {this.total = total;} private StringorderStr = "" Public String getOrderStr () {returnorderStr;} public void setOrderStr (String orderStr) {this.orderStr = orderStr;}}
Paging or non-paging sql does not need to be modified in xml; sql does not need additional processing for pageinfo, such as manual addition of limit or rownum; that does not require paging, PageInfo parameter is not passed; no additional count statistics sql is required
Select * from micro_test5 where condition=# {param}
Java calls Dao
When creating an instance in PageInfo, you need to enter pageNo (number of pages starting from 1) and pageRows (number of pages per page).
If sql does not have an orderby statement in xml, set pageInfo.setOrderStr () in pageInfo
/ / create the paging information object PageInfo pageInfo=new PageInfo (1Power10); / / Page 1, 10 entries per page / / you can set the order string (optional) pageInfo.setOrderStr ("id desc"); / / call dao and pass in pageInfoList list=testRep.queryInfoById (paramMap,pageInfo); System.out.println (list); / / use pageInfo.getTotal () to get the total number of records System.out.println (pageInfo.getTotal ())
Note:
1, Custom sort
If sql does not write a dead sort sql in xml, pageInfo can set the sort string. The advantage is that there is no need to sort when querying the number of records, and sorting sql is automatically spelled when querying records to improve query performance. You can also support flexible sorting without modifying the sql in xml.
2, total record number processing
The number of sql; records that do not have to write an additional query count is brought back in the total field set to the pageInfo object in the plug-in.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.