mybatis是基於結果集映射的,剛開始學習時不明白爲何映射文件中沒有配置對應的表,緣由是mybatis要手寫SQL.web
而sql執行後的結果封裝到resultMap。sql
<resultMap type="web.vo.OutProductVO" id="outProductRM">
<result property="customName" column="CUSTOM_NAME"/>
<result property="contractNo" column="CONTRACT_NO"/>
<result property="productNo" column="PRODUCT_NO"/>
<result property="cnumber" column="CNUMBER"/>
<result property="factoryName" column="FACTORY_NAME"/>
<result property="deliveryPeriod" column="DELIVERY_PERIOD"/>
<result property="shipTime" column="SHIP_TIME"/>
<result property="tradeTerms" column="TRADE_TERMS"/>
</resultMap>
<!-- 按船期查詢某個月的合同統計 -->
<select id="find" parameterType="string" resultMap="outProductRM">
select
c.custom_name,c.contract_no,to_char(c.delivery_period,'yyyy-MM-dd') as delivery_period,to_char(c.ship_time,'yyyy-MM-dd') as ship_time,c.trade_terms,
cp.product_no,concat(cp.cnumber,cp.packing_unit) as cnumber,cp.factory_name
from
(select contract_id,custom_name,contract_no,delivery_period,ship_time,trade_terms from contract_c) c
left join
(select contract_id,product_no,cnumber,packing_unit,factory_name from contract_product_c) cp
on c.contract_id=cp.contract_idmybatis
where to_char(c.ship_time,'yyyy-MM') = #{inputDate}
</select>
</mapper>app
它是比較靈活的,須要查什麼字段均可以。學習
可是相對於hibernate基於對象的映射 就會查出全部的字段在內存中。hibernate