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>  

     
  • 相关阅读:
    URL vs. HTML 录制模式
    多机联合产生负载
    浏览器打开URL的方式和加载过程
    与前端性能相关的头信息
    HTTP协议结构
    前端优化
    前端性能测试工具
    Apache 服务器
    java回调机制
    不允许用大于号小于号,比较任意两个数字大小
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/6183542.html
Copyright © 2011-2022 走看看