zoukankan      html  css  js  c++  java
  • ibatis中isEquals、isNotEmpty的用法

    一:isEquals用于动态拼接sql

    如下实例:

    如果status的状态为0,则更新attribute1;状态为1,则更新attribute2;

    状态为2,则更新attribute3。

    <update   id="topup.doEffect" parameterClass="java.util.HashMap">
    update  cis_customer  set  code_id  = #codeId# ,
    <isEqual property="status" compareValue="0" prepend=",">  
                attribute1=#attribute1#</isEqual>  
            <isEqual property="status" compareValue="1" prepend=",">  
                attribute2=#attribute2#</isEqual>  
            <isEqual property="status" compareValue="2" prepend=",">  
                attribute3=#attribute3#</isEqual>
    where  id = #id#
    </update>  

    二:isNotEmpty

    如下实例:

    查询cis_customer这张表,如果属性aaa不为空,则将条件aaa=#aaa#拼接;

    如果bbb不为空,则将条件bbb=#bbb#拼接;如果属性ccc不为空,则将条件ccc=#ccc#拼接;

     1 <select  id="topup.querySuccessCount" parameterClass="java.util.HashMap">
     2      select id,name from cis_customer where 1=1
     3      <isNotEmpty  property="aaa"  prepend="and">  
     4                  aaa=#aaa#
     5   </isNotEmpty  >  
     6   <isNotEmpty  property="bbb"  prepend="and">  
     7                  bbb=#bbb#
     8    </isNotEmpty  >  
     9    <isNotEmpty  property="ccc" prepend="and">  
    10                 ccc=#ccc#
    11   </isNotEmpty  >
    12   </select>  
  • 相关阅读:
    Explain 索引优化分析
    组合索引与前缀索引
    MySQL 索引的类型
    MySQL 字符集及校验规则
    MySQL 连接查询
    DQL 数据查询语言
    DML 数据操纵语言
    DCL 数据控制语言
    DDL 数据定义语言
    蓝桥杯大学B组省赛2020模拟赛(一)题解与总结
  • 原文地址:https://www.cnblogs.com/warrior4236/p/5978752.html
Copyright © 2011-2022 走看看