springboot(四)整合分页插件PageHelper

引入依赖


<dependency>
    <groupId>com.github.pagehelpergroupId>
    <artifactId>pagehelper-spring-boot-starterartifactId>
    <version>1.2.5version>
dependency>

配置数据库方言

传统的ssm框架整合PageHelper插件时一般是在SqlMapConfig.xml文件中配置

<plugins>
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <property name="dialect" value="mysql"/>
        plugin>
    plugins>

springboot只需要配置一行

#pagehelper分页插件配置
pagehelper:
  helper-dialect:mysql

mapper接口

 @Select("select * from account")
    Page selectAccounts();

service实现

   public Page selectAccount(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        Page accounts = accountMapper.selectAccounts();
        return accounts;
    }

controller

@RequestMapping("/selectAccount")
    public Page selectAccount(int pageNum,int pageSize){
        return accountService.selectAccount(pageNum,pageSize);
    }

结果

页面访问 http://localhost:8080/selectAccount?pageNum=1&pageSize=2
[{“id”:1,”name”:”aaa”,”money”:1000.0},{“id”:2,”name”:”bbb”,”money”:1000.0}]

你可能感兴趣的:(springboot,SpringBoot)