In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Paging query in Oracle is more complex to write because of the existence of pseudo-column rownum,sql statements. Now it is very convenient to introduce a paging query by using RowBounds in MyBatis.
When you use RowBounds in MyBatis for paging query, you do not need to write offset,limit,mybatis in the sql statement. Offset,limit,mybatis will automatically splice the paging sql and add offset,limit to achieve automatic paging.
You need to pass parameters currentPage and pageSize in the foreground, which are the current page and the number of pages, respectively. The controller layer can pass the parameters to the service layer. The following is the code for the service implementation:
Package com.xyfer.service.impl;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.ibatis.session.RowBounds;import com.xyfer.dao.UserDao;import com.xyfer.service.UserService;public class UserServiceImpl implements UserService {private UserDao userDao; @ Override public Map queryUserList (String currentPage, String pageSize) {/ / query total number of data int total = userDao.queryCountUser (); / / return result set Map resultMap = new HashMap () ResultMap.put ("total", total); / / Total pages int totalpage = (total + Integer.parseInt (pageSize)-1) / Integer.parseInt (pageSize); resultMap.put ("totalpage", totalpage); / / the starting line of the data int offset = (Integer.parseInt (currentPage)-1) * Integer.parseInt (pageSize); RowBounds rowbounds = new RowBounds (offset, Integer.parseInt (pageSize)) / / user data set List userList = userDao.queryUserList (rowbounds); resultMap.put ("userList", userList); return resultMap;}}
Dao layer interface:
Package com.xyfer.dao;import java.util.List;import java.util.Map;import org.apache.ibatis.session.RowBounds;public interface UserDao {public int queryCountUser (); / / query the total number of users public List queryUserList (RowBounds rowbounds); / / query user list}
Corresponding mapper.xml file:
Select count (1) from user select * from user
Paging query data can be achieved by passing in the corresponding parameters through the postman call API.
Summary
The above is the editor to introduce to you the Oracle uses RowBounds in MyBatis to achieve paging query function, hope to help you, if you have any questions, please leave me a message, the editor will reply you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
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.