使用PageHelper分页插件实现分页 https://pagehelper.github.io/
pom依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
yml配置文件
pagehelper:
helper-dialect: oracle
reasonable: true
params: count
support-methods-arguments: true
因为无法导入包,操作失败
使用mybatis-plus分页插件
pom依赖
<!-- 分页插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.1</version>
</dependency>
yml配置文件
mybatis:
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.sal.daisy.cargo_report.**.entity
configuration:
map-underscore-to-camel-case: true #大驼峰命名法
mybatis-plus:
mapper-locations: classpath:mapper/**/*.xml
type-aliases-package: com.sal.daisy.cargo_report.**.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 打印sql
配置文件
配置文件@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
测试
controller
@GetMapping("/userList")
public Result userList() {
int pageNum = 1;
int pageSize = 50;
IPage<User> page = new Page<>(pageNum, pageSize);
return Result.succuess(helloService.userList(page));
}
service
Page userList(IPage<User> page);
@Override
public Page userList(IPage<User> page) {
return userMapper.userList(page);
}
mapper
Page userList(IPage<User> page);
<select id="userList" resultType="com.sal.daisy.cargo_report.test.entity.User">
select user_id, username
from cargonest_sys.sys_user
</select>
查询成功
网友评论