引入PageHelper依赖
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.6</version> <!--使用spring boot2整合 pagehelper-spring-boot-starter必须排除一下依赖 因为pagehelper-spring-boot-starter也已经在pom依赖了mybatis与mybatis-spring 所以会与mybatis-plus-boot-starter中的mybatis与mybatis-spring发生冲突 --> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </exclusion> </exclusions> </dependency>
MoveBookQueryDto
public class MoveBookQueryDto { private String area; private String cartype; private Date startMoveDate; private Date endMoveDate; private String contact; private Integer status; private int pageNum; private int pageSize; }
MoveBookingService
PageInfo<MoveBooking> moveBookList(MoveBookQueryDto moveBookQueryDto);
MoveBookingServiceImpl
@Override public PageInfo<MoveBooking> moveBookList(MoveBookQueryDto moveBookQueryDto) { PageHelper.startPage(moveBookQueryDto.getPageNum(),moveBookQueryDto.getPageSize()); LambdaQueryWrapper<MoveBooking> moveBookingLambdaQueryWrapper = new LambdaQueryWrapper<>(); moveBookingLambdaQueryWrapper.eq(moveBookQueryDto.getArea()!=null,MoveBooking::getArea,moveBookQueryDto.getArea()) .eq(moveBookQueryDto.getCartype()!=null,MoveBooking::getCartype,moveBookQueryDto.getCartype()) .ge(moveBookQueryDto.getStartMoveDate()!=null,MoveBooking::getMovedate,moveBookQueryDto.getStartMoveDate()) .le(moveBookQueryDto.getEndMoveDate()!=null,MoveBooking::getMovedate,moveBookQueryDto.getEndMoveDate()) .eq(moveBookQueryDto.getContact()!=null,MoveBooking::getContact,moveBookQueryDto.getContact()) .eq(moveBookQueryDto.getStatus()!=null,MoveBooking::getStatus,moveBookQueryDto.getStatus()); List<MoveBooking> list = this.list(moveBookingLambdaQueryWrapper); if (CollectionUtils.isEmpty(list))return PageInfo.of(new ArrayList<>()); return PageInfo.of(list); }
MoveBookingController
@GetMapping("/list") public R<PageInfo<MoveBooking>> list(MoveBookQueryDto moveBookQueryDto){ PageInfo<MoveBooking> pageInfo = moveBookingService.moveBookList(moveBookQueryDto); return R.success(pageInfo); }
测试