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();
    }
}

 

posted @ 2019-11-09 17:54  &天涯海角&  阅读(3153)  评论(0编辑  收藏  举报