mybatis 嵌套查询list写法
·
public class BeanName implements Serializable{
private String id;
private String propertyName1;
private String propertyName2;
private String propertyName3;
private String propertyName4;
private List<PriceInfoDto> priceInfo; //子集1
private List<NumInfoDto> numInfo; //子集2
}
public class PriceInfoDto implements Serializable{
private String id;
private String name1;
private String name2;
private String name3;
private String name4;
}
public class NumInfoDto implements Serializable{
private String id;
private String name5;
private String name6;
private String name7;
private String name8;
}
<select id="findInfo" parameterType="com.xx.xxx" resultMap="totalInfoMap">
select
total.id as id,
total.column_name1 as propertyName1,
total.column_name2 as propertyName2,
total.column_name3 as propertyName3,
total.column_name4 as propertyName4,
price.name1 as name1,
price.name2 as name2,
price.name3 as name3,
price.name4 as name4,
num.name5 as name5,
num.name6 as name6,
num.name7 as name7,
num.name8 as name8
from table_total total left join table_num num on num.total_id = total.id
left join table_price price on price.total_id = total.id
where total.status = 0
and total.id = #{id}
</select>
<resultMap type="com.xx.BeanName" id="totalInfoMap">
<!-- property : bean中属性名称 column : 表中字段名称 -->
<id property="id" column="id"/>
<result property="propertyName1" column="column_name1"/>
<result property="propertyName2" column="column_name2"/>
<result property="propertyName3" column="column_name3"/>
<result property="propertyName4" column="column_name4"/>
<!-- ofType bean属性名称 -->
<collection property="priceInfo" ofType="com.xx.PriceInfoDto">
<result property="name1" column="name1"/>
<result property="name2" column="name2"/>
<result property="name3" column="name3"/>
<result property="name4" column="name4"/>
</collection>
<collection property="numInfo" ofType="com.xx.NumInfoDto">
<result property="name5" column="name5"/>
<result property="name6" column="name6"/>
<result property="name7" column="name7"/>
<result property="name8" column="name8"/>
</collection>
</resultMap>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)