ibatis&mybatis組裝動態查詢&排序
使用#orderItem#是會有問題的,ibatis會自動給你加上單引號,應該使用如下
<dynamic prepend="ORDER BY">
<isNotNull property="orderItem">
<![CDATA[
$orderItem$
]]>
</isNotNull>
<isNull property="orderItem">
a1.expiry_date
]]>
</isNull>
<isEqual property="orderRule" compareValue="1">
ASC
</isEqual>
<isEqual property="orderRule" compareValue="0">
</isEqual>
</dynamic>
例子:
<select id="findListByQuery" resultMap="promoteProductOrderRenewalDOResultMap" parameterClass="promoteProductOrderRenewalQuery" >
SELECT
<include refid="promoteProductOrderRenewal_do_columns" />
FROM promote_product_order_renewal a1
<include refid="doQueryParams" />
<dynamic prepend="ORDER BY">
<![CDATA[
$orderItem$
]]>
</isNotNull>
<isNull property="orderItem">
<![CDATA[
a1.expiry_date
]]>
</isNull>
<isEqual property="orderRule" compareValue="1">
ASC
</isEqual>
<isEqual property="orderRule" compareValue="0">
DESC
</isEqual>
</dynamic>
<isEqual property="page" compareValue="true">
limit #start#,#limit#
</isEqual>
</select>