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呢?

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题