MybatisPlus多表联查分页查询


//实现类中具体实现
 
 @Transactional
public PageUtils<Response(响应实体)> pageList(请求实体 index) {

//请求体中需要有页码及页大小参数
    Integer pageNum = index.getPageNum();
    Integer pageSize = index.getPageSize();
    Page<Response> iPage = new Page<>(pageNum, pageSize);

//param 用于存放查询条件
    Map <String,Long>params = new HashMap<>();

    if (index.getBoardId() != null) {
        params.put(Constant.INDEX_SET_BELONG_BOARD_ID,index.getBoardId());
    }
    if (index.getIndexId() != null) {
        params.put(Constant.INDEX_SET_SOURCE_ID, index.getIndexId());
     }

    IPage<Response> pageList = indexMapper.selectIndex(iPage, params);

    List<Response> list = pageList.getRecords();

    return new PageUtils<>(list, (int) iPage.getTotal(), pageSize, pageNum);
}
@Mapper
public interface IndexMapper extends BaseMapper<Index> {

//此处是重点  需要注意此处参数的格式   要加@Param注解,引号内是存放参数Map的名称
   IPage<Response> selectIndexSetCalcuConf(Page<IndexSetCalcuConfResponse> iPage, @Param("paramMap") Map <String,Long> paramMap);

}
<select id="selectIndexSetCalcuConf"  resultType="com.kaishu.bigdata.confcenter.vo.response.IndexSetCalcuConfResponse">
    select t1.id, t1.code,t1.sql, t1.user,t1.create_time,t1.update_time,
           t2.name,t3.type_name,t3.type,t4.board
    from
         conf t1
    left join
          source t2
    on t1.source_id = t2.id
    LEFT JOIN
          index t3
    on t1.type_id = t3.id
    LEFT JOIN
          report t4
   on t1.board_id = t4.id
  where
      1=1
      //注意下面判断语句 param.indexSetBelongBoardId 为判断map中是否有这个键,有接拼上这个条件语句
      //取值和判断条件一样
    <if test="paramMap.indexSetBelongBoardId != null">
        and t1.index_set_belong_board_id = #{paramMap.indexSetBelongBoardId}
    </if>
    <if test="paramMap.indexSetSourceId != null">
        and t1.index_set_source_id = #{paramMap.indexSetSourceId}
    </if>
    order by t1.update_time desc
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值