zoukankan      html  css  js  c++  java
  • Mybatis where 1=1 和 <where>标签

    <select id="selSampleListByIDX4" resultMap="BaseResultMap" parameterType="cn.com.git.cbs.datamodel.TBL_Sample">
    select
    <include refid="Base_Column_List" />
    from SAMPLE
    where 1=1
    <if test="samplenumber != null" >
    AND SAMPLENUMBER = #{samplenumber,jdbcType=DECIMAL}
    </if>
    </select>

    Mybatis  之前拼条件的时候 写法  where 1=1,也可以使用<where>标签

    <select id="findActiveBlogLike"
    resultType="Blog">
    SELECT * FROM BLOG
    <where>
    <if test="state != null">
    state = #{state}
    </if>
    <if test="title != null">
    AND title like #{title}
    </if>
    <if test="author != null and author.name != null">
    AND author_name like #{author.name}
    </if>
    </where>
    </select>

    where 元素知道只有在一个以上的if条件有值的情况下才去插入“WHERE”子句。而且,若最后的内容是“AND”或“OR”开头的,where 元素也知道如何将他们去除。

    如果 where 元素没有按正常套路出牌,我们还是可以通过自定义 trim 元素来定制我们想要的功能。比如,和 where 元素等价的自定义 trim 元素为:

     <trim prefix="WHERE" prefixOverrides="AND |OR "> ... </trim>  

     
  • 相关阅读:
    葵花宝典,参考学习网站收藏
    安卓工具
    马帮
    C89:vs输出调试信息
    OSG:中级篇 拖拽器类
    OSG:幼儿园篇 第六章 碰撞检测类
    OSG:幼儿园篇 第三章 节点坐标变换类
    OSG:幼儿园篇 第五章 界面交互类
    C++11:智能指针
    OSG:幼儿园篇 第四章 节点回调类
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/6183542.html
Copyright © 2011-2022 走看看