分页实现
# Mybatis-Plus
# 基础操作
controller
@GetMapping(value = "page" , name = "分页")
@PreAuthorize("@ss.hasPermi('system:config:list')")
public R page(SysConfigEntity sysConfigEntity) {
PageResult<SysConfigEntity> page = configService.page(sysConfigEntity);
return R.ok().put(page);
}
1
2
3
4
5
6
7
2
3
4
5
6
7
serviceImpl
@Override
public PageResult<SysConfigEntity> page(SysConfigEntity sysConfigEntity) {
return configMapper.selectPage(sysConfigEntity);
}
1
2
3
4
2
3
4
mapper
default PageResult<SysConfigEntity> selectPage(SysConfigEntity config) {
return selectPage(new LambdaQueryWrapperX<SysConfigEntity>()
.likeIfPresent(SysConfigEntity::getConfigName, config.getConfigName())
.likeIfPresent(SysConfigEntity::getConfigKey, config.getConfigKey())
.eqIfPresent(SysConfigEntity::getGroupCode, config.getGroupCode())
.betweenIfPresent(SysConfigEntity::getCreateTime, config.getParams())
);
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
LambdaQueryWrapperX
拓展 MyBatis Plus QueryWrapper
类,增加一些常用功能:
- 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。
# 拼接查询参数
可参考 SysUserService
@Override
public Page<SysUserEntity> selectAllocatedList(SysUserEntity user) {
Page<SysUserEntity> page = new PageQuery().buildPage();
QueryWrapper<SysUserEntity> wrapper = Wrappers.query();
wrapper.eq("u.del_flag", UserConstants.NORMAL)
.eq("r.role_id", user.getRoleId())
.eq(ObjectUtil.isNotNull(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber())
.like(ObjectUtil.isNotNull(user.getUserName()), "u.user_name", user.getUserName());
Page<SysUserEntity> sysUserPage = userMapper.selectAllocatedList(page, wrapper);
return sysUserPage;
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
xml文件传入
@Override
public Page<SysUserEntity> selectUnallocatedList(SysUserEntity user) {
Page<SysUserEntity> page = new PageQuery().buildPage();
return userMapper.selectUnallocatedList(page, user);
}
1
2
3
4
5
2
3
4
5
Page<SysUserEntity> selectUnallocatedList(@Param("page") Page<SysUserEntity> page, @Param("user") SysUserEntity user);
1
最后更新: 2023/11/27, 15:11:00