Spring Boot 中PageHelper 插件使用配置思路详解

网友投稿 1696 2022-12-17

Spring Boot 中PageHelper 插件使用配置思路详解

Spring Boot 中PageHelper 插件使用配置思路详解

使用思路

1.引入myabtis和pagehelphttp://er依赖

2

.yml中配置mybatis扫描和实体类

这2行代码

pageNum:当前第几页

pageSize:显示多少条数据

userList:数据库查询的数据数据列表

PageHelper.startPage(pageNum, pageSize);

PageInfo pageInfo = new PageInfo(userList);

最后返回一个pageInfo 对象即可,pageInfo 这个对象中只有数据一些信息,但是,没有成功失败的状态或者提示语。

真实企业中会封装一个返回对象,把pageInfo 放到对象中

1.pom依赖

方法一:使用原生的PageHelper

1.在pom.xml中引入依赖,刷新自动加载jar

pkPUnvZsF com.github.pagehelper

pagehelper

5.2.1

方法二 本人使用 PageHelper的starter

1.导入pom.xml依赖

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.12

2.在application.properties或者application.yml格式配置pagehelper的属性

二选一

#pagehelper分页插件配置application.properties

pagehelper.helper-dialect=mysql

pagehelper.reasonable=true

pagehelper.support-methods-arguments=true

pagehelper.params=count=countSql

application.yml

hepagehelper:

lperDialect: mysql

reasonable: true

supportMethodsArguments: true

params: count=countSql

Controller层调用 测试

@RequestMapping("findallCar")

public String findallCar(Model model, HttpSession session) {

PageHelpepkPUnvZsFr.startPage(1,5);

List carTables = service.findallCar();

PageInfo page = new PageInfo(carTables);

System.out.println(page);

model.addAttribute("carall", carTables);

session.setAttribute("caralls", carTables);

return "carinsert";

}

PageHelper.startPage(1,5);

List carTables = service.findallCar();

PageInfo page = new PageInfo(carTables);

System.out.println(page);

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:九个动画组图轮播总结全栈数据结构数组链表
下一篇:postman测试传入List<String>参数方式
相关文章

 发表评论

暂时没有评论,来抢沙发吧~