Mybatis框架中的resultMap高级映射---特殊问题(版本mybatis-3.5.5)
文章目录
多表关联查询时遇到的问题与结论:当使用多表关联查询时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>
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论