当前位置:网站首页>The use of PageHelper is simple and popular
The use of PageHelper is simple and popular
2022-07-21 23:15:00 【Nikon163】
I've seen many people's PageHelper Use , At first glance, it's so complicated , Tried several times without success , Now it's finally done . The key points have been thickened . The back end is really super simple , I think the front end is complex, so I can paste it directly .
The effect is as shown in the picture
I don't want to use PageInfo Entity classes are written by themselves ,PageHelper It's delicious .
PageHelper Use
Maven Plus dependence ( That is, the guide package )
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.1</version>
</dependency>
2. emphasis
One PageHelper.startPage(pageNum,pageSize);
There is another one PageInfo Wrap it up
It's that simple
@Override
public PageInfo<User> findByPage(Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<User> users = userDAO.selectByExample(null);
PageInfo<User> pageInfo = new PageInfo<>(users);
System.out.println(pageInfo);
return pageInfo ;
}
- Later, when retrieving
emphasize getList()!!!
Theoretically getList Is to get a non paged collection {pageNum,pageSize… A lot of …,List{userList}}
But the printing is strange ,list It's the same as before , But it's good when you use it , To the front is userList. It is estimated that toString What's wrong . Someone on the Internet said it was PageHelper Version of the problem , I changed it and still can't solve it .( Not affecting use )
@RequestMapping("findByPage")
@ResponseBody
public Map<String,Object> findByPage(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
Map<String,Object> resultMap = new HashMap<>();
try {
PageInfo<User> byPage = userService.findByPage(pageNum, pageSize);
System.out.println(byPage);
resultMap.put("page",byPage);
resultMap.put("userList",byPage.getList());
resultMap.put("result",true);
}catch (Exception e){
resultMap.put("result",false);
resultMap.put("message"," Paging query exception ");
}
return resultMap;
}
- Front end writing
pageMsg+='<li class="'+(data.page.pageNum==1?'disabled':'')+'"><a onclick="show('+(data.page.hasPreviousPage?data.page.prePage:data.page.pageNum)+')"> The previous page </a></li>';
for (var i = 1; i<=data.page.pages;i++){
pageMsg+='<li class="'+(data.page.pageNum==i?'active':'')+'"><a onclick="show('+i+')">'+i+' <span class="sr-only">(current)</span></a></li>';
}
pageMsg+='<li class="'+(data.page.isLastPage?'disabled':'')+'"><a onclick="show('+(data.page.hasNextPage?data.page.nextPage:data.page.pageNum)+')"> The next page </a></li>';
$("#byPage").html(pageMsg);
边栏推荐
- "Export animationclip" of unity customization tool
- Hcip day 10
- 四路病房呼叫系统
- HCIA_NAT实验
- 【 信息搜集的内容,信息搜集的方法,信息搜集的工具,信息搜集结果的利用等】
- OSPF and mGRE comprehensive experiment
- Why does okcc call center introduce voice into the web?
- HCIA学习思路
- The unity model enters from outside the camera, and the camera does not play the specified action
- mongoDB复杂查询实例(嵌套多个数组和正则表达式使用)
猜你喜欢
随机推荐
静态路由简单练习
HCIP MGRE综合实验
Comprehensive experiment of static routing
HCIP第二天综合实验
HCIA static comprehensive experiment
Hcip day 1 operation
log4j的简单配置
Static routing experiment
Unity customized gadget "export atlas pictures"
OSPF的不规则区域
第三天 网络类型
防火墙的原理、主要技术、部署及其优缺点
MySql可重复读的进一步认识
HCIP:ospf第一节
Hcip day 6
List Set Map Queue Deque Stack的遍历方式总结
HCIP day1
OSPF experiment in mGRE environment
[contents, methods, tools and results of information collection]
四台交换机2台pc实现全网可达