renr 2017-02-04 06:05 采纳率: 0%
浏览 2104

mybatis3.3 配置嵌套查询时,无法调用关联的select

<resultMap type="com.rr.one2many.Department" id="deptMap">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
    <!-- <collection property="emps" ofType="com.rr.one2many.Employee" javaType="java.util.ArrayList" column="id" select="empNamespace.findEmpById"></collection>
     -->
     <collection property="emps" column="id" select="findEmpById" ></collection>
</resultMap>

<select id="findAll" resultType="com.rr.one2many.Department">
    select * from department
</select>

<select id="findById" parameterType="int" resultType="com.rr.one2many.Department">
    select id,name from department where id=#{id}
</select>

<select id="findEmpById" parameterType="int" resultType="com.rr.one2many.Employee">
    select * from employee where depId=#{id}
</select>

<select id="findEmpById" parameterType="int" resultType="com.rr.one2many.Employee">
    select * from employee where depId=#{id}
</select>

<select id="findEmpByEmpId" parameterType="int" resultType="com.rr.one2many.Employee">
    select id,name,depId from employee where id=#{id}
</select>

<resultMap type="com.rr.one2many.Employee" id="empMap">
    <id property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="age" column="age"/>
    <association property="dept" javaType="com.rr.one2many.Department" column="depId" select="deptNamespace.findById"></association>
</resultMap>

员工表和部门表,查询部门时,获取关联的员工,或者查询员工时,获取关联的部门。但是执行某个select时,不会执行关联select。
比如,执行findEmpByEmpId,但是assocation中select对应的deptNamespace.findById"不执行
没有使用懒加载

  • 写回答

3条回答 默认 最新

  • S1ow 2017-02-04 07:48
    关注

    select中resultType改成对应的resultMap
    你这样写当然不会执行了,返回均为实体,根本没有走自定义的resultMap,又怎么能执行assocation呢?

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大