目录
- 模糊、分页、不统计数量、使用自定义的selectByPage方法,传入参数Page和LambdaQueryWrapper
- 模糊、分页、统计数量、使用自定义的selectByPage方法,传入参数Page和LambdaQueryWrapper
代码案例
- 模糊、分页、不统计数量、使用自定义的selectByPage方法,传入参数Page和LambdaQueryWrapper
@Component
public interface UserMapper extends BaseMapper {
IPage selectByPage(IPage userPage, @Param(Constants.WRAPPER) Wrapper userWrapper);
}
@RequestMapping("/test4")
@ResponseBody
public String test4(){
// 构建wrapper对象
LambdaQueryWrapper userLambdaQueryWrapper = Wrappers.lambdaQuery();
// 模糊查询
userLambdaQueryWrapper.like(User::getUsername , "a");
// 分页
Page mapPage = new Page<>(1, 2, false);
// 调用mapper层方法
IPage mapIPage = userMapper.selectByPage(mapPage , userLambdaQueryWrapper);
System.out.println("总页数: "+mapIPage.getPages());
System.out.println("总记录数: "+mapIPage.getTotal());
// 打印出查询结果
mapIPage.getRecords().forEach(System.out::println);
return "success";
}
- 模糊、分页、统计数量、使用自定义的selectByPage方法,传入参数Page和LambdaQueryWrapper
@RequestMapping("/test")
@ResponseBody
public String test(){
Integer current = 1;
Integer size = 3;
String username = "c";
String sex = "1";
// 构建wrapper对象
LambdaQueryWrapper userLambdaQueryWrapper = Wrappers.lambdaQuery();
// 构建page
Page mapPage = new Page<>(current, size, true);
// 调用mapper层方法
IPage mapIPage = userMapper.selectByPage(username, sex, mapPage , userLambdaQueryWrapper);
System.out.println("总页数: "+mapIPage.getPages());
System.out.println("总记录数: "+mapIPage.getTotal());
// 打印出查询结果
mapIPage.getRecords().forEach(System.out::println);
return "success";
}
IPage selectByPage(@Param("username") String username, @Param("sex") String sex, IPage userPage, Param(Constants.WRAPPER) Wrapper userWrapper);