当前位置:编程学习 > JAVA >>

ibatis如何判断是否存在where

我想在1条查询后面加上xx=11

但是这个查询是动态sql,可能会有where条件,可能没有

如果没有我就需要写成 where xx=11,有的话我就不需要

请问下如何判断有where就不再加where了


--------------------编程问答--------------------
<statement id="dynamicGetAccountList" resultMap="account-result" > 
  select * from ACCOUNT 
    <dynamic prepend="WHERE"> 
      <isNotNull prepend="AND" property="firstName"> 
        ACC_FIRST_NAME = #firstName# 
      </isNotNull>
      <isNotNull prepend="AND" property="lastName"> 
        ACC_LAST_NAME = #lastName# 
      </isNotNull> 
      <isNotNull prepend="AND" property="emailAddress"> 
        ACC_EMAIL like #emailAddress# 
      </isNotNull> 
      <isGreaterThan prepend="AND" property="id" compareValue="0"> 
        ACC_ID = #id# 
    </isGreaterThan> 
  </dynamic> 
  order by ACC_LAST_NAME 
</statement>
--------------------编程问答-------------------- 不是有<dynamic><isNotNull 节点吗 --------------------编程问答-------------------- 感觉sql要是没有嵌套的话indexof就可以,要是有的话还没想好... --------------------编程问答-------------------- isNotNull不是自动判断吗? --------------------编程问答-------------------- where 1=1 后面直接加查询条件,这样就不存在要不要where的问题了
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,