resultType 和resultMap 的区别?
生活随笔
收集整理的這篇文章主要介紹了
resultType 和resultMap 的区别?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
resultType 是<select>標簽的一個屬性,適合簡單對象(POJO、JDK 自帶類型:Integer、String、Map 等),只能自動映射,適合單表簡單查詢。
<select id="selectAuthor" parameterType="int" resultType="com.leon.domain.Author">select author_id authorId, author_name authorNamefrom author where author_id = #{authorId} </select>resultMap 是一個可以被引用的標簽,適合復雜對象,可指定映射關系,適合關聯復合查詢。
<resultMap id="BlogWithAuthorResultMap"type="com.leon.domain.associate.BlogAndAuthor"><id column="bid" property="bid" jdbcType="INTEGER"/><result column="name" property="name" jdbcType="VARCHAR"/><!-- 聯合查詢,將author 的屬性映射到ResultMap --><association property="author" javaType="com.leon.domain.Author"><id column="author_id" property="authorId"/><result column="author_name" property="authorName"/></association> </resultMap>?
總結
以上是生活随笔為你收集整理的resultType 和resultMap 的区别?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手写自己的MyBatis框架-V2.0
- 下一篇: collection 和associat