在项目中使用了ibatis的dynamic动态语句,如下
<select id="getRecommends" parameterClass="java.util.Map" resultClass="Long">
select hrp.product_id
from HOT_RECOMMEND_PRODUCT hrp
where hrp.category_id = #categoryId#
and hrp.mc_site_id = #mcsiteId#
<![CDATA[
and hrp.start_time >= trunc(sysdate)
and hrp.end_time <= trunc(sysdate)
]]>
<dynamic prepend="and">
<isNotNull prepend="and" property="merchantId">
hrp.merchant_id like '%' || #merchantId# || '%'
</isNotNull>
<isNotEqual prepend="and" property ="siteType" compareValue="0">
hrp.site_type = #siteType#
</isNotEqual>
<isEqual prepend="or" property="siteType" compareValue="0">
hrp.merchant_id is null
</isEqual>
</dynamic>
order by hrp.PRIORITY_DISPLAY
</select>本项目为一个maven项目,编译成功后,在target下找到对应的文件中的sql语句,是正常的(同上)。但是部署到tomcat中后,再找到对应文件中的sql语句,就成了下面的这个样子了
<select id="getRecommends" parameterClass="java.util.Map" resultClass="Long">
select hrp.product_id
from HOT_RECOMMEND_PRODUCT hrp
where hrp.category_id = #categoryId#
and hrp.merchant_id like '%' || #merchantId# || '%'
and hrp.mc_site_id = #mcsiteId#
and hrp.start_time <= trunc(sysdate)
and hrp.end_time >= trunc(sysdate)
order by hrp.PRIORITY_DISPLAY
</select>tomcatibatismavensqldynamic
<select id="getRecommends" parameterClass="java.util.Map" resultClass="Long">
select hrp.product_id
from HOT_RECOMMEND_PRODUCT hrp
where hrp.category_id = #categoryId#
and hrp.mc_site_id = #mcsiteId#
<![CDATA[
and hrp.start_time >= trunc(sysdate)
and hrp.end_time <= trunc(sysdate)
]]>
<dynamic prepend="and">
<isNotNull prepend="and" property="merchantId">
hrp.merchant_id like '%' || #merchantId# || '%'
</isNotNull>
<isNotEqual prepend="and" property ="siteType" compareValue="0">
hrp.site_type = #siteType#
</isNotEqual>
<isEqual prepend="or" property="siteType" compareValue="0">
hrp.merchant_id is null
</isEqual>
</dynamic>
order by hrp.PRIORITY_DISPLAY
</select>本项目为一个maven项目,编译成功后,在target下找到对应的文件中的sql语句,是正常的(同上)。但是部署到tomcat中后,再找到对应文件中的sql语句,就成了下面的这个样子了
<select id="getRecommends" parameterClass="java.util.Map" resultClass="Long">
select hrp.product_id
from HOT_RECOMMEND_PRODUCT hrp
where hrp.category_id = #categoryId#
and hrp.merchant_id like '%' || #merchantId# || '%'
and hrp.mc_site_id = #mcsiteId#
and hrp.start_time <= trunc(sysdate)
and hrp.end_time >= trunc(sysdate)
order by hrp.PRIORITY_DISPLAY
</select>tomcatibatismavensqldynamic
<isNotNull prepend="and" property="merchantId">
hrp.merchant_id like '%' || #merchantId# || '%'
</isNotNull>
<isNotEqual prepend="and" property ="siteType" compareValue="0">
hrp.site_type = #siteType#
</isNotEqual>
<isEqual prepend="or" property="siteType" compareValue="0">
hrp.merchant_id is null
</isEqual>
</dynamic>上面对应的字段是否为空?
dynamic 会自动去除第一个 prepend="and中的内容(这里为and)
是我把项目的发布输出路径给设置错了。
我把class和test-class都设置成可以输出到tomcat中,导致test-class中的文件把class中的相同文件给覆盖了