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>  

     
  • 相关阅读:
    [国家集训队] Crash 的文明世界
    [国家集训队] middle
    [正睿集训2021] 构造专练
    [正睿集训2021] LIS
    CF482E ELCA
    UVA
    UVA
    UVA
    UVA
    UVA
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/6183542.html
Copyright © 2011-2022 走看看