操作记录:
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>()这么写就不报错了。