Springboot2.X + MybatisPlus3.4 自定义多表关联 分页查询

Mybatis 自定义多表关联查询

由于业务场景需要实现复杂的关联查询,自定义sql实现比较方便,所以记录一下

配置文件

mybatis-plus:
  mapper-locations: classpath*:/mapper/*.xml
  type-aliases-package: com.xxx.entity

初始化分页插件

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return mybatisPlusInterceptor;
    }

Mapper

    //注解方式
    @Select("select * from event where app_id= #{appId} and module_id = #{moduleId}")
    List<EventDefineInfo> selectEventByParam(@Param("appId") Integer appId, @Param("moduleId") Integer moduleId);

	//自定义SQL
    Page<Event> selectByPage(Page<EventDefineInfo> page, @Param("defineInfo") Event info);

mapper.xml

   <select id="selectByPage" resultType="Event">
        select evt.id,  evt.event_name,
               evt.module_id,mdu.module_name,
               evt.sub_module_id,sub.category_name,
               evt.update_by,evt.update_time
        from event evt
                 left join module mdu on evt.module_id = mdu.id
                 left join sub_module sub on evt.sub_module_id = sub.id
        where evt.app_id = #{info.appId}
        <if test="info.eventName != null and info.eventName != ''" >
            AND evt.event_name like CONCAT('%',#{info.eventName},'%')
        </if>
        <if test="info.eventId != null and info.eventId != ''" >
            AND evt.event_id = #{info.eventId}
        </if>

    </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值