zb51500618 2016-06-20 03:40 采纳率: 83.3%
浏览 1843
已采纳

mybatis 多级级联问题

在mybatis里面

当有三张表 o,u,ui 我想用o表查到ui的数据

返回类型是 o 时 ,这个resultMapper 改怎么写呢?
下面这个mapper 的写法是对的吗?

 select o.* ,ui.id as ui_id,ui.name as ui_name from order o, u_user u LEFT JOIN u_userinfo ui ON u.`id`=ui.`user_id`
 where  o.user_id = u.id 

 <resultMap id="fuckJiLianResult" type="com.ronhan.ctoc.model.Review">
    <id column="id" jdbcType="BIGINT" property="id" />

    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="score1" jdbcType="TINYINT" property="score1" />
    <result column="score2" jdbcType="TINYINT" property="score2" />
    <result column="score3" jdbcType="TINYINT" property="score3" />
    <result column="comments" jdbcType="VARCHAR" property="comments" />

      <association column="user" property="user" javaType="com.ronhan.ctoc.model.User" resultMap="userResult"/>
     </collection>
     </resultMap>
       <resultMap id="userResult" type="com.ronhan.ctoc.model.User">
        <id column="id" jdbcType="BIGINT" property="id" />
         <association column="userInfo" property="userInfo" javaType="com.ronhan.ctoc.model.UserInfo" resultMap="userInfoResult"/>
    </resultMap>
    <resultMap id="userInfoResult" type="com.ronhan.ctoc.model.UserInfo">
    <id column="ui_id" jdbcType="BIGINT" property="id" />

    <result column="ui_name" jdbcType="VARCHAR" property="name" />

    <result column="ui_buys" jdbcType="Integer" property="buys" />
  </resultMap>
  • 写回答

1条回答 默认 最新

  • yu954663801 2016-06-20 03:57
    关注

    MyBatis不需要指定对应关系,只需查询的字段名和JavaBean属性名对应即可,Hibernate才要这样指定。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?
  • ¥15 如何自动更换布娃娃图片上的衣服