当前位置:   article > 正文

springboot分页查询——pagehelper_springboot 怎么集成pagehealper -baijiahao

springboot 怎么集成pagehealper -baijiahao

1导入相应的包

	<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.2.3</version>
    </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5

2yml中配置相应文件

pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
  • 1
  • 2
  • 3
  • 4
  • 5

3mapper层

//查询页面所有数据
    List<Employee> queryForList(Object query);
  • 1
  • 2

4.service

/分页查询(page是list集合)
    Page<Employee> queryForPage(Object query);
  • 1
  • 2

impl

 @Override
    public Page<Employee> queryForPage(Object query) {
        //设置当前页,和每页条数
        PageHelper.startPage(1, 10);
        //查询获得所有页数
        List<Employee> employees = employeeMapper.queryForList(query);
        //强转
        Page<Employee> page = (Page<Employee>)employees;
        return page;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

mapper.xml

<select id="queryForList" resultType="cn.itsource.springboot.domain.Employee">
        select
        id,
        username,
        password
        from t_employee
    </select>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

controller

//分页查询
    @RequestMapping("/page")
    @ResponseBody
    public Page<Employee> queryForList(){
        //需要放一个query进去
        return employeeService.queryForPage(new Object());
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/676951
推荐阅读
相关标签
  

闽ICP备14008679号