1. 写一个正常的sql 查询自己想要的数据的外层


<resultMap id="getChild" type="com.kx.whpcomp.oem.application.dangeroem.entity.DangerOemTemplateLink" >
<id column="id" property="id"/>
<result column="danger_check_group_id" property="dangerCheckGroupId"/>
</resultMap>
<select id="getCheckItem" parameterType="java.util.Map" resultMap="getChild">
select t.*,tt.danger_range dangerCheckGroupName
from t_whp_danger_oem_template_link t
left join t_whp_danger_oem_check_group tt on t.danger_check_group_id = tt.id
where 1=1
<if test="pd.templateId != null and pd.templateId != '' ">
and t.danger_template_id = #{pd.templateId}
</if>
GROUP BY t.danger_check_group_id
</select>
2. 实体类中增加子集的集合

3. 返回resultmap的结果中增加collection

property : 属性名( 2 中的属性名)
javaType:属性名的类型
column: 配置查询sql的参数名( qq: 查询子集的参数,danger_check_group_id:1 中sql查询出的字段名)
select: 查询的方法名
ofType:查询子集的实体类(包含全路径)
<resultMap id="getChild" type="com.kx.whpcomp.oem.application.dangeroem.entity.DangerOemTemplateLink" >
<id column="id" property="id"/>
<result column="danger_check_group_id" property="dangerCheckGroupId"/>
<collection property="checkItem" javaType="ArrayList" column="{qq=danger_check_group_id}" select="getCheckItems" ofType="com.kx.whpcomp.oem.application.dangeroem.entity.DangerOemCheckItem">
</collection>
</resultMap>
<resultMap id="itemBase" type="com.kx.whpcomp.oem.application.dangeroem.entity.DangerOemCheckItem" ></resultMap>
<select id="getCheckItems" parameterType="java.util.Map" resultMap="itemBase">
select * from t_whp_danger_oem_check_item a where a.danger_group_id = #{qq}
</select>
4. 实现 3 中的查询方法


1969

被折叠的 条评论
为什么被折叠?



