用log4j把prepareStatment打出来看看。这样看太受伤了。

解决方案 »

  1.   

    是因为你这段没加 and 吧:
    <isEmpty property="consignmentDate1"><isNotEmpty property="consignmentDate2">CONSIGNED_DATE &lt;![CDATA[ < ]]&gt;#consignmentDate2#</isNotEmpty></isEmpty>
    <isNotEmpty property="consignmentDate1"><isEmpty property="consignmentDate2">CONSIGNED_DATE &lt;![CDATA[ > ]]&gt;#consignmentDate1#</isEmpty></isNotEmpty>
    <isNotEmpty property="consignmentDate1"><isNotEmpty property="consignmentDate2">CONSIGNED_DATE between #consignmentDate1# and #consignmentDate1#</isNotEmpty></isNotEmpty>
      

  2.   

    你写得好复杂,像and这样的操作符可以不用写到语句中的,给你段与你类似的例子:
    <select id="qryIllegallogHisCunt" parameterClass="smsLog" resultClass="java.lang.Integer">

    select count(*) from t_hist_log_uncommon 
    <dynamic prepend="where">
    <isNotEmpty prepend="and" property="beginDate">
    <![CDATA[convert(char(8),occur_time,112)>=#beginDate#]]>
    </isNotEmpty>
    <isNotEmpty prepend="and" property="endDate">
    <![CDATA[convert(char(8),occur_time,112) <= #endDate#]]>
    </isNotEmpty>
    <isNotEmpty prepend="and" property="teleCompany">
    tele_company_type=#teleCompany#
    </isNotEmpty>
    <isNotEmpty prepend="and" property="serialNo">
    serial_no=#serialNo#
    </isNotEmpty>
    </dynamic>
    </select>
    实现按日期查询!与你功能不一样在于输入单个时我是按>=而你是按>,可以按你自己的要求改进!
      

  3.   

    应该把实际执行的SQL写入到LOG中
    然后从LOG中看实际的SQL语句
      

  4.   

    要实现你的需求,建议改为直接由SQL语句来实现比较方便,以下以Oracle为例  and (
           (CONSIGNED_DATE > #consignmentDate1# 
              and CONSIGNED_DATE < #consignmentDate2#
              and #consignmentDate1# is not null
              and #consignmentDate2# is not null)
           or
           (CONSIGNED_DATE < #consignmentDate2#
              and #consignmentDate1# is not null
              and #consignmentDate2# is null)
           or
           (CONSIGNED_DATE > #consignmentDate2#
              and #consignmentDate1# is null
              and #consignmentDate2# is not null)
          )