<resultMap id="deptResultMap"
type="com.inspur.pms.pojo.dept.DeptVO">
<id column="dept_id" jdbcType="INTEGER" property="dept_id" />
<result column="dept_name" jdbcType="VARCHAR"
property="dept_name" />
<result column="parent_dept_id" jdbcType="INTEGER"
property="parent_dept_id" />
<result column="parent_dept_name" jdbcType="VARCHAR" property="parent_dept_name" />
<result column="dept_desc" jdbcType="VARCHAR"
property="dept_desc" />
<collection property="rel_role" ofType="java.lang.Integer">
<result column="role_id"/>
</collection>
</resultMap>
<select id="selectByIds" resultMap="deptResultMap">
select d1.dept_id,dept_name,parent_dept_id,dept_desc,
(SELECT dept_name from dept d2 where d1.parent_dept_id=d2.dept_id)
parent_dept_name ,rd.role_id
from dept d1
LEFT JOIN role_dept rd on rd.dept_id=d1.dept_id
where d1.dept_id in
<foreach collection="dept_ids" item="dept_id" index="no"
open="(" separator="," close=")">
#{dept_id}
</foreach>
order by sort
</select>
主要想的有3个地方
<collection property="rel_role" ofType="java.lang.Integer">
<result column="role_id"/>
</collection>
还有sql语句中 LEFT JOIN role_dept rd on rd.dept_id=d1.dept_id