多表关联查询时遇到的问题与结论:当使用多表关联查询时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>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。