collection 和association 的区别?
生活随笔
收集整理的這篇文章主要介紹了
collection 和association 的区别?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
association:一對一
<!-- 另一種聯合查詢(一對一)的實現,但是這種方式有“N+1”的問題--> <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:一對多、多對多
<!-- 查詢文章帶評論的結果(一對多) --> <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> <!-- 按作者查詢文章評論的結果(多對多) --> <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>?
?
?
總結
以上是生活随笔為你收集整理的collection 和association 的区别?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: resultType 和resultMa
- 下一篇: PrepareStatement 和St