Mybatis的<where><trim><set>标签使用和排重
来源:互联网 发布:n卡负优化a卡战未来 编辑:程序博客网 时间:2024/05/08 07:38
trim标签可以很好地兼容where和set的功能
只要你在trim标签中的prefix中使用对应的关键字,就可以达到相应的作用
所以where和set可以不用啦
先对比一下mybatis中trim的几个参数的作用
prefixOverrides :是取消前面的多余内容,比如where语句中的and
suffixOverrides :是取消后缀的多余内容,比如set中的逗号
先说prefixOverrides
<sql id="whereExcludeIp"><if test="exd_id !=null and exd_id !=''">AND exi.exd_id = #{exd_id}</if><if test="ip_addr_outer !=null and ip_addr_outer !=''">AND exi.ip_addr_outer like CONCAT('%',#{ip_addr_outer},'%')</if><if test="port_outer !=null and port_outer !=''">AND exi.port_outer like CONCAT('%',#{port_outer},'%')</if><if test="ip_addr_inner !=null and ip_addr_inner !=''">AND exi.ip_addr_inner like CONCAT('%',#{ip_addr_inner},'%')</if></sql>
使用见下面
<!-- 查询受限ip信息 --><select id="findExcludeIpInfo" parameterType="Map" resultType="Map"><include refid= "selExcludeIp" /><include refid= "fromExcludeIp" /><trim prefix="WHERE" prefixOverrides="AND|OR"><include refid= "whereExcludeIp" /> </where></select>
接下来是suffixOverrides
<update id="updateExcludeIpInfo" parameterType="Map">UPDATE tb_exclude_ip<trim prefix="SET" prefixOverrides=","> <if test="used_status !=null and used_status !='' "> used_status = #{used_status}, </if> <if test="used_status !=null and used_status !='' "> used_status = #{used_status}, </if> </set>WHERE exd_id = #{exd_id}</update>
上面的代码中的第二个if语句中的逗号可能无用,所以这样可以将它失效。 0 0
- Mybatis的<where><trim><set>标签使用和排重
- mybatis中<where>标签、<set>标签、<trim>标签、<sql>标签、<foreach>标签的使用
- Mybatis的<where><foreach><set><trim>等标签详解
- Mybatis中的三个标签<where> <set> <trim>
- Mybatis动态标签--trim,where,set
- Mybatis <where> <if> <set> <trim> <choose>标签
- mybatis的动态SQL(三)where、set、trim标签的使用
- Mybatis的<where><foreach><set><trim>详解
- Mybatis 使用<where>标签时遇到的一个问题与<trim>标签的使用
- Mybatis trim标签的使用
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- Mybatis的动态sql----where,trim,set,foreach
- Mybatis的动态sql----where,trim,set,foreach
- MyBatis动态SQL之 set 和 trim标记的使用
- MyBatis动态SQL之 set 和 trim标记的使用
- Mybatis的<where><foreach><set>标签详解
- mybatis <where> <set>标签的作用
- ubuntu mysql 安装和外网访问配置
- SQL Server中的Merge关键字
- thinkphp的select和find的区别
- 第十三周项目5---拓扑排序算法验证
- Java 遍历Map时 删除元素
- Mybatis的<where><trim><set>标签使用和排重
- 线性表-双向链表
- Book1-Unit5
- Java-值传递or引用传递
- SSM问题1:Error configuring application listener of class org.springframework.web.context.ContextLoader
- Python 中requests 模块text 和content 差别
- Book2-Unit1
- jQuery UI 实例 - 对话框(Dialog)
- SQL 特殊函数应用