SpringBoot如何集成PageHelper分页功能
添加MyBatis的代码并修改以下部分:
1.添加MyBatisConfig
packagemyshop.config; importjava.util.Properties; importorg.springframework.context.annotation.Bean; importorg.springframework.context.annotation.Configuration; importcom.github.pagehelper.PageHelper; @Configuration publicclassMyBatisConfig{ @Bean publicPageHelperpageHelper() { System.out.println("UsePageHelper"); PageHelperpageHelper=newPageHelper(); Propertiesp=newProperties(); p.setProperty("offsetAsPageNum","true"); p.setProperty("rowBoundsWithCount","true"); p.setProperty("reasonable","true"); pageHelper.setProperties(p); returnpageHelper; } }
2.修改MyBatisController
packagemyshop.controller; importjava.util.List; importorg.springframework.beans.factory.annotation.Autowired; importorg.springframework.web.bind.annotation.RequestMapping; importorg.springframework.web.bind.annotation.RestController; importcom.github.pagehelper.PageHelper; importmyshop.bean.UserInfo; importmyshop.service.MyBatisService; @RestController publicclassMyBatisController{ @Autowired privateMyBatisServicemyBatisService; @RequestMapping("likeName") publicListlikeName(Stringusername) { PageHelper.startPage(1,2); returnmyBatisService.likeName(username); } }
3.访问地址
http://localhost:8080/likeName?username=天恒
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。