提示:现在要写一个sql以及关联一个子查询,而子查询传入参数和父查询一致
例如:接口传参为platIdList,这个列表不仅要作为主查询条件还是子查询条件,这里需要把传参转为字符串并作为返回列传给子查询,由于从list->String所以使用find_in_set或者转为list处理
<resultMap id="config" type="java.util.HashMap">
<collection property="deptIdList" column="{platIdList=platIdList}" javaType="java.util.ArrayList" select="getDeptId"/>
</resultMap>
<select id="getDeptId" resultType="java.lang.Long">
SELECT DISTINCT id
FROM dept
WHERE FIND_IN_SET(plat_id, REPLACE(REPLACE(#{platIdList}, '[', ''), ']', '')) > 0;
</select>
<select id="getDeptInfo" resultMap="config">
SELECT GROUP_CONCAT(DISTINCT dept_name) AS deptNames,'${platIdList}' as platIdList
FROM dept
WHERE plat_id in
<foreach collection="platIdList" item="platId" open="(" separator="," close=")">
#{platId}
</foreach>
</select>
1204

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



