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