Springboot分页插件使用实例解析
更新时间:2019年11月11日 09:17:11 作者:&天涯海角&
这篇文章主要介绍了Springboot分页插件使用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了Springboot分页插件使用实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
在springboot工程下的pom.xml中添加依赖
<!--分页 pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency>
在工程的配置Application文件中添加如下代码
#pagehelper分页插件配置 pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql
对service层的更改
@Service public class UserService2 { @Autowired private UserDao userDao; public PageInfo<User> queryAll(Integer page, Integer pageSize ){ PageHelper.startPage(page,pageSize);//分页起始码以及每页页数 List<User> users=userDao.selectAll(); PageInfo pageInfo=new PageInfo(users); return pageInfo; }
对controller层的更改
@Controller public class UserController2 { @Autowired private UserService2 userService2; @RequestMapping("queryAll") @ResponseBody public List<User> query(@RequestParam(value="page",defaultValue="1")Integer page, @RequestParam(value="pageSize",defaultValue="2")Integer pageSize){ PageInfo<User> pageInfo=userService2.queryAll(page,pageSize); return pageInfo.getList(); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
详解在IDEA中使用MyBatis Generator逆向工程生成代码
这篇文章主要介绍了详解在IDEA中使用MyBatis Generator逆向工程生成代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-06-06Springboot下swagger-ui.html访问不到的解决方案
这篇文章主要介绍了Springboot下swagger-ui.html访问不到的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-10-10
最新评论