前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Mapper文件在select语句中使用

Mapper文件在select语句中使用

原创
作者头像
用户8983410
修改2021-10-08 14:55:38
7320
修改2021-10-08 14:55:38
举报

非常复杂的结果集合,Mapper文件可能长这个样子,(注意当我们在select语句中使用B.title as blog_title,在resultMap的<result property="title" column="blog_title"/> 可以不设,系统会自动映射生成<result property="title" column="blog_title"/>,但是加上更清晰,也不会增加系统负担)如下:

代码语言:javascript
复制
<!-- Very Complex Result Map -->  
<resultMap id="detailedBlogResultMap" type="Blog">  
  <constructor>  
    <idArg column="blog_id" javaType="int"/>  
  </constructor>  
  <result property="title" column="blog_title"/>  
  <association property="author" javaType="Author">  
    <id property="id" column="author_id"/>  
    <result property="username" column="author_username"/>  
    <result property="password" column="author_password"/>  
    <result property="email" column="author_email"/>  
    <result property="bio" column="author_bio"/>  
    <result property="favouriteSection" column="author_favourite_section"/>  
  </association>  
  <collection property="posts" ofType="Post">  
    <id property="id" column="post_id"/>  
    <result property="subject" column="post_subject"/> 
    <!-- 由于自动映射等级为:PARTIAL,自动的映射author_id;同时注意上面对Author类已经映射过了, -->  
    <association property="author" javaType="Author"/>  
    <collection property="comments" ofType="Comment">  
      <id property="id" column="comment_id"/>  
    </collection>  
    <collection property="tags" ofType="Tag" >  
      <id property="id" column="tag_id"/>  
    </collection>  
    <discriminator javaType="int" column="draft">  
      <case value="1" resultType="DraftPost"/>  
    </discriminator>  
  </collection>  
</resultMap>  

  注意上面是以Blog为中心,来找对应的作者,对应的文章,对应的评论和标签。下面,开始详细说明每一个元素,请读者一定按照单元测试的方法推进,千万不要一次性配置大量属性,以免影响学习兴趣。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档