当前位置: 代码迷 >> J2EE >> ibatis select count(*) 有关问题
  详细解决方案

ibatis select count(*) 有关问题

热度:295   发布时间:2016-04-22 03:17:32.0
ibatis select count(*) 问题
sqlMap文件配置:
XML code
<select id="getLetters" parameterClass="java.util.HashMap" resultMap="Letter">        SELECT * FROM zzb_introletter WHERE introDate>=#introDate#         <isNotEmpty prepend="AND" property="toDate">            <![CDATA[                introDate<=#toDate#            ]]>        </isNotEmpty>        <isNotEmpty prepend="AND" property="introDir">            introDir = #introDir#        </isNotEmpty>            <isNotEmpty prepend="AND" property="introSrc">            introSrc = #introSrc#        </isNotEmpty>        <isNotEmpty prepend="AND" property="introDes">            introDes = #introDes#        </isNotEmpty>        <isNotEmpty prepend="AND" property="memberName">            memberName = #memberName#        </isNotEmpty>        <isNotNull prepend=" " property="orderKey">            <isNotEqual prepend=" " property="orderKey"                compareValue="UNDEFINED">            ORDER BY $orderKey$ $orderValue$            </isNotEqual>        </isNotNull>        <isNotEmpty prepend=" " property="limit">            limit #limit# offset #start#        </isNotEmpty>    </select>    <select id="getCount" parameterClass="java.util.HashMap" resultClass="int">        SELECT COUNT(*) FROM zzb_introletter  WHERE introDate>=#introDate#         <isNotEmpty prepend="AND" property="toDate">            <![CDATA[                introDate<=#toDate#            ]]>        </isNotEmpty>        <isNotEmpty prepend="AND" property="introDir">            introDir = #introDir#        </isNotEmpty>            <isNotEmpty prepend="AND" property="introSrc">            introSrc = #introSrc#        </isNotEmpty>        <isNotEmpty prepend="AND" property="introDes">            introDes = #introDes#        </isNotEmpty>        <isNotEmpty prepend="AND" property="memberName">            memberName = #memberName#        </isNotEmpty>    </select>


这是使用ibatis动态生成sql语句的功能查询的,上面那个select是查询一页的内容,下面那个select是查询数目,可以看到查询条件除了上面有个
XML code
<isNotNull prepend=" " property="orderKey">            <isNotEqual prepend=" " property="orderKey"                compareValue="UNDEFINED">            ORDER BY $orderKey$ $orderValue$            </isNotEqual>        </isNotNull>        <isNotEmpty prepend=" " property="limit">            limit #limit# offset #start#        </isNotEmpty>

排序和限制条数的条件外,都是一样的,但是运行的时候,上面那个select正常,下面这个select count(*)的总是不正常,返回的结果总是0,当我传入introDate和toDate 两个参数的时候,日志输出这样的:
 Connection
 Preparing Statement: SELECT * FROM zzb_introletter WHERE introDate>=? AND introDate<=? ORDER BY introId desc limit ? offset ?  
 //这里为了节省空间,省略结果输出,有好几条结果的

 Connection
 Preparing Statement: SELECT COUNT(*) FROM zzb_introletter WHERE introDate>=?  
 ResultSet
 Header: [COUNT(*)]
 Result: [0]  
 //大家瞅瞅,我两次传入的条件是一样的但是结构就是0,sql语句select count(*)的条件总是不全。。
 是不是我的配置有问题,请高手指点

------解决方案--------------------
  相关解决方案