mybatis 中collection 對應List

    <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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章