collection 和association 的区别?
生活随笔
收集整理的這篇文章主要介紹了
collection 和association 的区别?
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
association:一對(duì)一
<!-- 另一種聯(lián)合查詢(一對(duì)一)的實(shí)現(xiàn),但是這種方式有“N+1”的問(wèn)題--> <resultMap id="BlogWithAuthorQueryMap" type="com.leon.domain.associate.BlogAndAuthor"><id column="bid" property="bid" jdbcType="INTEGER"/><result column="name" property="name" jdbcType="VARCHAR"/><association property="author" javaType="com.leon.domain.Author"column="author_id" select="selectAuthor"/> <!-- selectAuthor 定義在下面--> </resultMap>collection:一對(duì)多、多對(duì)多
<!-- 查詢文章帶評(píng)論的結(jié)果(一對(duì)多) --> <resultMap id="BlogWithCommentMap" type="com.leon.domain.associate.BlogAndComment"extends="BaseResultMap" ><collection property="comment" ofType="com.leon.domain.Comment"><id column="comment_id" property="commentId" /><result column="content" property="content" /></collection> </resultMap> <!-- 按作者查詢文章評(píng)論的結(jié)果(多對(duì)多) --> <resultMap id="AuthorWithBlogMap" type="com.leon.domain.associate.AuthorAndBlog" ><id column="author_id" property="authorId" jdbcType="INTEGER"/><result column="author_name" property="authorName" jdbcType="VARCHAR"/><collection property="blog" ofType="com.leon.domain.associate.BlogAndComment"><id column="bid" property="bid" /><result column="name" property="name" /><result column="author_id" property="authorId" /><collection property="comment" ofType="com.leon.domain.Comment"><id column="comment_id" property="commentId" /><result column="content" property="content" /></collection></collection> </resultMap>?
?
?
總結(jié)
以上是生活随笔為你收集整理的collection 和association 的区别?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: resultType 和resultMa
- 下一篇: PrepareStatement 和St