我想写一个delete语句,但是条件是根据不同情况设置的,所以加了一个变量delType, 想delType=1 按照id删,delType=2 按照name删,delType=3按照type删。
前三种比较好写:
             <isEqual prepend="and" property="delType" compareValue="1">
                ID=#id#
             </isEqual>
             <isEqual prepend="and" property="delType" compareValue="2">
                NAME=#name#
             </isEqual>
             <isEqual prepend="and" property="delType" compareValue="3">
                TYPE=#type#
             </isEqual>但是如果delType不是1、2、3中的任何一个,我还想执行另外一个条件,这样怎么写?或者delType只要是1、2、3当中的任何一个执行相同的语句,这个又怎么写?

解决方案 »

  1.   

    写个方法 返回boolean  传一个参数 在sql中判断
    如果boolean返回true就删除成功 false就调用别的方法
      

  2.   

    sql 里面条件 id||name||type=参数值 试试吧 我做过这样的查询 删除没试过 希望对你有帮助
      

  3.   


    <sql id="where">
    <dynamic prepend="where">
    <isNotNull property="id">
    <isGreaterEqual prepend="and" property="id"
    compareValue="0">
    id = #id:int#
    </isGreaterEqual>
    </isNotNull>
    <isNotNull property="title">
    <isNotEmpty prepend="and" property="title">
    title = #title:varchar#
    </isNotEmpty>
    </isNotNull>
    <isNotNull property="thefile">
    <isNotEmpty prepend="and" property="thefile">
    thefile = #thefile:varchar#
    </isNotEmpty>
    </isNotNull>
    </dynamic>
    </sql>写成非空判断就行了