Mybatis-plus 笔记

操作记录:

Mybatis-----查询结果合并成集合_小大宇的博客-CSDN博客_mybatis合并结果集

转载总结为

@Data
public class Subsystem {
    private int subsystemId;
    private String subsystemKey;
    private String subsystemName;
    private Integer sn;
    private boolean selected;
    //持有Page对象集合
    private List<Page> pages;
}

@Data
public class Page {
    private int pageId;
    private String pageKey;
    private String pageName;
    private boolean selected;
    private Integer parentPageId;
    private Integer sn;
    private List<Page> subPages;
<select id="list" resultMap="listWithPage">
         SELECT
             ts.id,
             ts.subsystem_key,
             ts.subsystem_name,
             tp.id as page_id,
             tp.page_key,
             tp.page_name,
             ts.SN,
             tp.SN as page_sn,
             tp.parent_page_id
         FROM t_subsystem ts
         LEFT JOIN t_page tp ON ts.id = tp.subsystem_id
         ORDER BY ts.SN , tp.SN
    </select>

    <resultMap id="listWithPage"  
               <!-- 这里返回最终的对象类型-->
               type="${package}.Subsystem">
        <id property="subsystemId" column="id"/>
        <result property="subsystemName" column="subsystem_name"/>
        <result property="subsystemKey" column="subsystem_key"/>
        <result property="sn" column="sn"/>
        <collection property="pages" 
                       <!-- 这里填写持有的集合对象类型-->
                     ofType="${package}.Page">
            <id property="pageId" column="page_id"/>
            <result property="pageKey" column="page_key"/>
            <result property="pageName" column="page_name"/>
            <result property="sn" column="page_sn"/>
            <result property="parentPageId" column="parent_page_id"/>
        </collection>
    </resultMap>

坑:

1.Mybatis-plus-join

Non-static method 'xxx' cannot be referenced from a static context

MPJLambdaWrapper query = new MPJLambdaWrapper<Company>()
        .selectAs(Group::getId, CompanyRspDto::getGroupId)
        .selectAs(Group::getName, CompanyRspDto::getGroupName);
query.innerJoin(OrgCompanyGroup.class, OrgCompanyGroup::getCompanyId, Company::getId)

这一句报Non-static method  cannot be referenced from a static context

编译报错:
java: 对于innerJoin(java.lang.Class<com.fusionfintrade.auth.entity.OrgCompany>,OrgCompany[...]anyId,Company::getId), 找不到合适的方法
    方法 com.github.yulichang.wrapper.interfaces.LambdaJoin.innerJoin(java.lang.Class,com.baomidou.mybatisplus.core.toolkit.support.SFunction,com.baomidou.mybatisplus.core.toolkit.support.SFunction)不适用
      (参数不匹配; 方法引用无效
          无法将 类 com.fusionfintrade.auth.entity.OrgCompany中的 方法 getCompanyId应用到给定类型
            需要: 没有参数
            找到: java.lang.Object
            原因: 实际参数列表和形式参数列表长度不同)
    方法 com.github.yulichang.wrapper.interfaces.LambdaJoin.innerJoin(boolean,java.lang.Class,com.github.yulichang.wrapper.interfaces.on.OnFunction)不适用
      (参数不匹配; java.lang.Class<com.fusionfintrade.auth.entity.OrgCompany>无法转换为boolean)

最后发现是MPJLambdaWrapper<Company> query = new MPJLambdaWrapper<Company>()这么写就不报错了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MPJLambdaWrapper是一个用于构建多表查询条件的工具类。它可以通过select方法指定查询的字段,通过leftJoin方法指定连表查询的条件。在实际使用中,可以通过MPJLambdaWrapper构建查询条件,然后调用相应的方法进行查询。\[1\] 在多表查询中,可以使用select方法指定查询的字段,但每个select只能查询一个表的字段。可以使用leftJoin方法指定参与连表查询的实体类和连表的ON字段,其中第一个参数是参与连表的实体类,第二个参数是连表的ON字段,第三个参数是参与连表的ON的另一个实体类属性。默认情况下,主表的别名是t,其他表的别名以先后调用的顺序使用t1、t2、t3等。\[2\] MPJLambdaWrapper还支持条件查询,可以查询主表以及参与连接的所有表的字段,并且使用了MP原生的方法,没有SQL注入的风险。在一对多查询中,可以使用selectCollection方法指定一对多查询的字段,并使用leftJoin方法指定连表查询的条件。\[3\] #### 引用[.reference_title] - *1* *2* [MyBatis-Plus实现多表联查](https://blog.csdn.net/xujx321/article/details/129708003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [mybatis plus join基于mybatis plus的连表插件](https://blog.csdn.net/bjdiys/article/details/129456271)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值