使用mybatisPlus自带的分页方法+xml实现数据分页
:因为需要实现多表关联分页,原本想的是直接使用@select+pagehelper,但是pagehelper只对xml文件生效;后面发现可以直接使用mybatisplus自带的分页,不依靠pagehelper实现多表关联分页;
实现类:关键代码:
Page<TgjZhuanKePaiMingVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());创建分页对象
/*** 查询国家专科排名数据列表*/@Overridepublic TableDataInfo<TgjZhuanKePaiMingVo> queryPageList(TgjZhuanKePaiMingBo bo, PageQuery pageQuery) {//查询医院级别字典Map<String, String> hosp_level = iSysDictTypeService.selectDictDataByType("hosp_level").stream().collect(Collectors.toMap(SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel));//医院类型字典Map<String, String> hosp_class = iSysDictTypeService.selectDictDataByType("hosp_class").stream().collect(Collectors.toMap(SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel));//所属地区字典Map<String, String> hosp_area = iSysDictTypeService.selectDictDataByType("hosp_area").stream().collect(Collectors.toMap(SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel));Page<TgjZhuanKePaiMingVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());IPage<TgjZhuanKePaiMingVo> zhuanKePaiMingList = baseMapper.getZhuanKePaiMingList(page, hosp_level.get(bo.getHospLevel()), hosp_class.get(bo.getHospClass()),hosp_area.get( bo.getHospArea()), bo.getHospName());// 返回封装后的分页数据return TableDataInfo.build(zhuanKePaiMingList);}
mapper层:关键把
Page<?> page作为分页参数传递
IPage<TgjZhuanKePaiMingVo> getZhuanKePaiMingList(Page<?> page, @Param("hospLevel")String hospLevel, @Param("hospClass")String hospClass,@Param("hospArea")String hospArea, @Param("hospName")String hospName);
xml:这里我用的返回结果是reulttype因为我的类和数据库中的字段是驼峰对应的,不一致的字段需要使用resultmap来进行一一映射,包括如果返回结果包含了类类型或者集合类型也是需要使用resultmap进行映射
<select id="getZhuanKePaiMingList" resultType="org.yunshu.keyspecialty.domain.vo.TgjZhuanKePaiMingVo">SELECTa.id,a.nian_fen,b.hosp_name AS yi_yuan_ming_cheng,a.zhuan_ke_dai_ma,a.zhuan_ke_ming_cheng,a.zhuan_ke_zhi,a.pai_ming,a.dang_wei,b.hosp_level,b.hosp_class,b.hosp_area,b.hosp_gradeFROMTgj_zhuan_ke_pai_ming aLEFT JOINsys_hospital bONa.yi_yuan_id = b.hosp_idWHERE1 = 1<if test="hospLevel != null and hospLevel != ''">AND b.hosp_level = #{hospLevel}</if><if test="hospClass != null and hospClass != ''">AND b.hosp_class like convert(#{hospClass},'%')</if><if test="hospArea != null and hospArea != ''">AND b.hosp_area = #{hospArea}</if><if test="hospName != null and hospName != ''">AND b.hosp_name LIKE CONCAT(#{hospName}, '%')</if></select>