多表关联查询时遇到的问题与结论:当使用多表关联查询时collection中的property属性(menuIds)不能为数组(Integer[]),只能写成集合List<Integer>


封装类
@Data
public class SysRoleMenu implements Serializable{

    private static final long serialVersionUID = 8377897338767610433L;
    private Integer id;
    private String name;
    private String note;
    private Integer[] menuIds; //应该改成List<Integer>
}
数据层接口方法Dao

基于id查询,返回一个SysRoleMenu类型的对象

SysRoleMenu selectRole(Integer id);
XML中的SQL语句
<resultMap type="com.cy.pj.sys.pojo.SysRoleMenu" id="findRoleMenu">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="note" column="note"/>
    <collection property="menuIds" ofType="integer">   
        <result column="menu_id"/>
    </collection>
</resultMap>
<select id="selectRoleMenu" resultMap="findRoleMenu">
    select u.id,u.name,u.note,r.menu_id
    from sys_roles u left join sys_role_menus r 
    on u.id=r.role_id
    where u.id=#{id}
</select>

嵌套查询时collection中的property属性(menuIds)可以是数组(Integer[]),也可以是集合List<Integer>


summer
30 声望3 粉丝

这一路我披荆斩棘,只为遇见你