在项目中使用了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 &lt;= trunc(sysdate)
           and hrp.end_time &gt;= trunc(sysdate)
 order by hrp.PRIORITY_DISPLAY
</select>tomcatibatismavensqldynamic

解决方案 »

  1.   

    clean啊啥的都试过,在同事的电脑上也是这个样子,但是我另外一个工程确实正常的。没发现区别啊
      

  2.   

    <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>上面对应的字段是否为空?
     dynamic 会自动去除第一个 prepend="and中的内容(这里为and)
      

  3.   

    我把正常的代码拷贝到对应的tomcat的对应文件中,业务数据一切正常。所以sql应该是不会有问题?我另外一个项目的代码里没有使用isEqual和isNotEqual这两个标签,不知道是否和这个有关。  我实验下
      

  4.   

    你是说应用启动,在运行过程中,打印sql是否正确么?这样的话,是不行的,问题就是在运行的时候发现的,然后一路追查发现是tomcat在部署的时候,动态语句给弄错了
      

  5.   

    谢谢各位了,已经找到原因了。
    是我把项目的发布输出路径给设置错了。
    我把class和test-class都设置成可以输出到tomcat中,导致test-class中的文件把class中的相同文件给覆盖了