不废话直接上码。
Role 类:根据角色得到资源
Power 类:{ 资源
 
 private String leftpowerId;
 
 
 private LeftPower leftPower; // 左菜单资源 
}
那么我在roleMapper.xml{
     <resultMap type="com.mybatis.ssoft.model.Power" id="role_power_resultMap">
 <id property="id" column="ID"/>
 <result property="powerName" column="POWERNAME"/>
 <result property="iconCls" column="ICONCLS"/>
 <result property="rank" column="RANK"/>
 
 <result property="leftpowerId" column="LEFTPOWERID"/>
 <!-- 加载左边资源列表 -->
  <association property="leftPower" column="LEFTPOWERID" 
  javaType="com.mybatis.ssoft.model.LeftPower" resultMap="power_leftPower" />
 
 
 <!-- 递归自身children -->
 <association property="parentPower" column="CHILDREN" javaType="com.mybatis.ssoft.model.Power">
 <id property="id" column="ID"/>
 <result property="powerName" column="POWERNAME"/>
 <result property="iconCls" column="ICONCLS"/>
 <result property="rank" column="RANK"/>
 <association property="attributes" column="RESOURCEPOWERID" 
 javaType="com.mybatis.ssoft.model.PowerResource" resultMap="C"/>
 <!-- 此处省略 leftPower -->
 </association>
 
 
 
 <!-- 加载权限资源url -->
 <association property="attributes" column="RESOURCEPOWERID" 
 javaType="com.mybatis.ssoft.model.PowerResource" resultMap="C"/>
 
 
 </resultMap>
 
 
 <!-- 资源路径集合 -->
 <resultMap type="com.mybatis.ssoft.model.PowerResource" id="C">
 <id property="id" column="ID"/>
 <result property="url" column="URL"/>
 </resultMap>
 
 
}
 
 
其中棕色字体就是报错的:
Error getting nested result map values for 'leftPower'. Cause: java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.mybatis.ssoft.dao.RoleMapper.power_leftPower
其中
resultMap="power_leftPower" 对应的文件LeftPowerMapper.xml
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.mybatis.ssoft.dao.LeftPowerMapper">
 <resultMap type="com.mybatis.ssoft.model.LeftPower" id="power_leftPower"> 
 
 <id property="id" column="ID"/>
 <result property="leftPowerName" column="LEFTPOWERNAME"/>
 <result property="leftPowerContext" column="LEFTPOWERCONTEXT"/>
 <result property="iconCls" column="ICONCLS"/>
 <result property="rank" column="RANK"/>
 <association property="topPower" column="TOPPWERID" javaType="com.mybatis.ssoft.model.TopPower" resultMap="A"/> 
 
 </resultMap>
 
 
 
 
 
 
 </mapper>
 
 排版不太好,请见谅
 
 
 
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
少了命名空间!
应该是resultMap=" com.mybatis.ssoft.dao.LeftPowerMapper.power_leftPower "
而不是resultMap=" power_leftPow"
系统异常已经很清楚的告诉你在“com.mybatis.ssoft.dao.RoleMapper”下面没有这个“ power_leftPow”!
PS:为什么不使用代码格式排版,那样看起来很痛苦,别人也不大乐意看你的问题!
把resultMap="power_leftPower"写在同一个mapper.xml 文件下试试
<associationproperty="leftPower"column="LEFTPOWERID"leftPower对应的字段是LEFTPOWERID
resultMap="power_leftPower" 里没这个字段的,只有ID
把resultMap="power_leftPower"写在同一个mapper.xml 文件下试试
<associationproperty="leftPower"column="LEFTPOWERID"leftPower对应的字段是LEFTPOWERID
resultMap="power_leftPower" 里没这个字段的,只有ID
少了命名空间!
应该是resultMap=" com.mybatis.ssoft.dao.LeftPowerMapper.power_leftPower "
而不是resultMap=" power_leftPow"
系统异常已经很清楚的告诉你在“com.mybatis.ssoft.dao.RoleMapper”下面没有这个“ power_leftPow”!
PS:为什么不使用代码格式排版,那样看起来很痛苦,别人也不大乐意看你的问题!