zoukankan      html  css  js  c++  java
  • MyBatis的where语句作用

    where语句的作用主要是简化SQL语句中where中的条件判断的,先看一个例子,再解释一下where的好处。

        <select id="dynamicWhereTest" parameterType="Blog" resultType="Blog">
            select * from t_blog
            <where>
                <if test="title != null">
                    title = #{title}
                </if>
                <if test="content != null">
                    and content = #{content}
                </if>
                <if test="owner != null">
                    and owner = #{owner}
                </if>
            </where>
        </select>
    where元素的作用是会在写入where元素的地方输出一个where,另外一个好处是你不需要考虑where元素里面的条件输出是什么样子 的,MyBatis会智能的帮你处理,如果所有的条件都不满足那么MyBatis就会查出所有的记录,如果输出后是and 开头的,MyBatis会把第一个and忽略,当然如果是or开头的,MyBatis也会把它忽略;此外,在where元素中你不需要考虑空格的问 题,MyBatis会智能的帮你加上。像上述例子中,如果title=null, 而content != null,那么输出的整个语句会是select * from t_blog where content = #{content},而不是select * from t_blog where and content = #{content},因为MyBatis会智能的把首个and 或 or 给忽略。java-javascript 风之境地

  • 相关阅读:
    构建SpringBoot第一个Demo
    SpringBoot简介
    JSJ——主数据类型和引用
    CSS3--动态实现ToolTip效果(实例)
    JavaScript--DOM事件(笔记)
    CSS3--幽灵按钮特效(实例)
    CSS3--实现特殊阴影 (实例)
    深入浅出ExtJS 第七章 弹出窗口
    深入浅出ExtJS 第六章 布局
    深入浅出ExtJS 第五章 树形结构
  • 原文地址:https://www.cnblogs.com/sky7034/p/2317725.html
Copyright © 2011-2022 走看看