mybatis一对多,多对一关系resultMap写法

来源:互联网 发布:日本人学中文 知乎 编辑:程序博客网 时间:2024/05/22 05:09

场景:博客下有文章集合,并且有关联作者对象

resultMap

<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"/>    <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>
原创粉丝点击