一. 效果展示
二. 代码编写
2.1 pom
< dependency> < groupId> com.baomidou</ groupId> < artifactId> mybatis-plus-boot-starter</ artifactId> < version> 3.4.2</ version>
</ dependency>
2.2 添加配置类
@Configuration
@MapperScan ( "scan.your.mapper.package" )
public class MybatisPlusConfig { @Bean public MybatisPlusInterceptor mybatisPlusInterceptor ( ) { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor ( ) ; interceptor. addInnerInterceptor ( new PaginationInnerInterceptor ( DbType . MYSQL ) ) ; return interceptor; }
}
2.3 前端选择条件实体
@Data
public class ApproveGetDto { private String startTime; private String endTime; private Integer approveStatus; private List < String > division; private String personScope; private String importPernr; private String quitPernr; private Integer currentPage; private Integer pageSize;
}
2.4 mapper添加分页方法
Page < UserVo > selectPageVo ( @Param ( "page" ) Page < UserVo > page, @Param ( "approveGetDto" ) ApproveGetDto approveGetDto) ;
2.5 sql映射文件
< select id = " selectPageVo" resultMap = " UserVo" > select * from t_user< where> < if test = " startTime != null and endTime != null" > AND importTime between #{startTime} and #{endTime}</ if> < if test = " division != null and division.size() > 0" > AND division in< foreach item = " item" collection = " division" open = " (" separator = " ," close = " )" > #{item}</ foreach> </ if> < if test = " personScope != null and personScope != ''" > AND person_scope = #{personScope}</ if> < if test = " importPernr != null and importPernr != ''" > AND originator_pernr = #{importPernr}</ if> < if test = " quitPernr != null and quitPernr != '' " > AND quit_Pernr = #{quitPernr}</ if> </ where>
</ select>
2.6 service
Page < UserVo > findPageVo ( ApproveGetDto approveGetDto) ;
2.7 serviceImpl
@Override
public Page < UserVo > selectPageVo ( ApproveGetDto approveGetDto) { Page < UserVo > page = new Page < UserVo > ( approveGetDto. getCurrentPage, approveGetDto. getPageSize) ; userMapper. selectPageVo ( page, approveGetDto) ; return page;
}
2.8 controller
@GetMapping ( "/page" )
public Result < Page < UserVo > > pageInfo ( ApproveGetDto approveGetDto) { Page < UserVo > userVo = userService. findPageVo ( approveGetDto) ; return Result . success ( userVo) ;
}
2.9 前端获取参数
getList ( ) { this . loading = true this . queryParams. currentPage = this . currentPagethis . queryParams. pageSize = this . pageSizeapproveDataList ( this . queryParams) . then ( response => { if ( response. code == 200 ) { if ( response. data. total == 0 ) { this . approveDataList = response. data. rowsthis . $alert ( '未查询到符合条件的数据,请检查查询条件后重试!' , '查询结果' , { confirmButtonText : '确定' , } ) this . loading = false } else { this . totalCount = response. data. totalthis . approveDataList = response. data. recordsthis . $message ( { message : '查询成功' , type : 'success' } ) this . loading = false } } else { this . loading = false this . approveDataList = [ ] this . $message ( { message : '查询失败' , type : 'erro' } ) } } )
}
三. 参数
System . out. println ( page. getRecords ( ) ) ;
System . out. println ( page. getPages ( ) ) ;
System . out. println ( page. getTotal ( ) ) ;
System . out. println ( page. hasNext ( ) ) ;
System . out. println ( page. hasPrevious ( ) ) ;