SpringBoot中 Mybaties PageHelper插件使用

1.引入包

注意:如果报错或者不能分页,很可能是版本号不对

<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>1.3.1</version>
</dependency>
<dependency>
	<groupId>com.github.pagehelper</groupId>
	<artifactId>pagehelper-spring-boot-starter</artifactId>
	<version>1.2.3</version>
</dependency>

2.如果需要对pagehelper进行设置在application.yml中加入以下设置

pagehelper:
  helperDialect: mysql
  reasonable: true
  support-methods-arguments: true
  params=count: ountSql

3.使用

PageHelper.startPage(pageNum, pageSize);

此方法是在mybatis查询语句之前进行拦截注意:此方法紧跟查询语句之前,这样才安全.

4.代码片段

public PageInfo<TaskLog> getPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TaskLog> taskLogs = taskLogMapper.selectAll();
        PageInfo<TaskLog> pageInfo= new PageInfo<>(taskLogs);
        return pageInfo;
    }

猜你喜欢

转载自blog.csdn.net/qq_41648302/article/details/83145621