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

这篇文章主要介绍了Spring Boot 中pageHelper 插件使用配置及实现思路,通过引入myabtis和pageHelper依赖,在yml中配置mybatis扫描和实体类,具体实现方法跟随小编一起看看吧

使用思路

1.引入myabtis和pageHelper依赖2.yml中配置mybatis扫描和实体类这2行代码pageNum:当前第几页pageSize:显示多少条数据userList:数据库查询的数据数据列表pageHelper.startPage(pageNum, pageSize);PageInfo pageInfo = new PageInfo(userList);最后返回一个pageInfo 对象即可,pageInfo 这个对象中只有数据一些信息,但是,没有成功失败的状态或者提示语。真实企业中会封装一个返回对象,把pageInfo 放到对象中

1.pom依赖

方法一:使用原生的pageHelper1.在pom.xml中引入依赖,刷新自动加载jarcom.github.pageHelperpageHelper5.2.1方法二 本人使用 pageHelper的starter1.导入pom.xml依赖com.github.pageHelperpageHelper-spring-boot-starter1.2.122.在application.properties或者application.yml格式配置pageHelper属性二选一#pageHelper分页插件配置application.propertiespageHelper.helper-dialect=MysqL pageHelper.reasonable=true pageHelper.support-methods-arguments=true pageHelper.params=count=countsqlapplication.ymlhepageHelper: lperDialect: MysqL reasonable: true supportMethodsArguments: true params: count=countsqlController层调用 测试@RequestMapping("findallCar") public String findallCar(Model model, HttpSession session) { pageHelper.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);到此这篇关于Spring Boot 中pageHelper 插件使用配置思路详解的文章就介绍到这了,更多相关Spring Boot pageHelper 插件内容搜索编程之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程之家!

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...