概述
IPage分页插件
①Mapper 定义分页查询接口,入参及返回值需要有IPage类型
IPage<PatientInfo> getPatientPage(IPage<PatientInfo> page,@Param("option") QueryOption option);
②编写映射文件xml
<select id = "getPatientPage" resultMap="getPatientPageMap">
select *
from view_patient_info
<where>
<if test="option.patientId != null">
and patient_id = #{option.patientId}
</if>
</where>
</select>
③在service中调用mapper接口
public IPage<PatientInfo> getPatientInfoPage(QueryOption option){
IPage<PatientInfo> page = new Page<>(option.getPageNum(),option.getPageSize());
baseMapper.getPatientPage(page,option);
return page;
}
这样就可以了。
PageHelper
①引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
②在service中调用mapper接口
PageHelper不需要在Mapper接口中加入Page参数,可以直接用原先的Mapper里的List查询接口。
public PageInfo<PatientInfo> getPatientInfoPage(QueryOption option){
PageHelper.startPage(option.getPageNum(),option.getPageSize());
List<PatientInfo> list = baseMapper.getPatientList(option);
PageInfo<PatientInfo> pageInfo = new PageInfo<>(list);
return pageInfo;
}
总结:
IPage是MybatisPlus自带的插件,不需要额外引入依赖,但查询分页需要定义包含IPage类型的参数的专门接口。
PageHelper需要引入额外的依赖,但不强制要求使用包含分页参数的专门接口,可以直接使用已有的List查询接口。
另外它们返回的数据结构也有一点小区别。前端对接的时候要注意。
最后
以上就是清新美女为你收集整理的PageHelper与MyBatisPlus IPage分页插件的使用区别的全部内容,希望文章能够帮你解决PageHelper与MyBatisPlus IPage分页插件的使用区别所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复