mybatis 中 查詢結果進行自定義的配置
阿新 • • 發佈:2019-01-28
當mybatis的結果集是可以對映成為一個entity的時候,
這個時候的配置是比較簡單的 resultType=”org.huluo.Entity”直接是包名加上類名就可以了。
但是如果select出來的東西有groupby 和entity屬性不匹配的時候,我們可以這樣進行配置
···
<select id="getDownloadNumberPerMonth" resultMap="caseDownloadNumberPerMonthResultMap"> SELECT date_format(create_date,'%m') as month,count(*) as downloadNumberPerMonth from ana_download WHERE ana_download.id= #{id} GROUP BY month </select>
···
<resultMap id="caseDownloadNumberPerMonthResultMap" type="java.util.Map">
<result column="month" property="month" jdbcType="VARCHAR"/>
<result column="downloadNumberPerMonth" property="downloadNumberPerMonth" jdbcType="VARCHAR"/>
</resultMap>
如果是隻有一行記錄的結果集的話,mybatis會吧結果包裝成Map