美文网首页
Mybatis--动态SQL(choose--when--oth

Mybatis--动态SQL(choose--when--oth

作者: 何以解君愁 | 来源:发表于2022-07-30 02:44 被阅读0次

choose--when--otherwise:相当于if...else if...else
(与if标签的区别:用if时,条件都要执行,choose,when,otherwise只要一个满足条件后面就不再执行因此不需要and)

<select id="getEmpBycondition" resultType="Emp">
    select*from t_emp
    <trim prefix=where>
        <choose>
            <when test="empName != null and empName != ''">
                emp_name =#{empName} 
            </when>
            <when test="age != null and age != "'">
                age = #{age} 
            </when>
            <when test="empName != null and empName != ''">
                emp_name =#{ empName} 
            </when>
            <otherwise>
                id=1
            </otherwise>
        </choose>
    </trim>
</select>

相关文章

  • Mybatis--动态SQL(choose--when--oth

    choose--when--otherwise:相当于if...else if...else(与if标签的区别:用...

  • MyBatis--多表查询

    接着上篇MyBatis--动态SQL[https://www.jianshu.com/p/368f4d951eae...

  • MyBatis--动态SQL

    接着上篇MyBatis--代理模式实现数据库增删改查[https://www.jianshu.com/p/d70b...

  • Mybatis--动态SQL(foreach,sql)

    foreach标签:collection:当前要循环的数组或集合 item:数组中的每一个数据 separato...

  • Mybatis--动态SQL(if,where,trim)

    Mybatis框架的动态SQL技术是一种根据特定条件动态拼接SQL语句的功能,作用是为了解决拼接SQL语句字符串的...

  • MyBatis学习:动态sql

    1.动态sql 动态sql是mybatis中的一个核心,什么是动态sql?动态sql即对sql语句进行灵活操作,通...

  • MyBatis--注解式开发

    MyBatis--注解式开发 MyBatis的注解,主要是用于替换映射文件。而映射文件中无非存放着增删改查的sql...

  • 第十三章 使用动态SQL(一)

    第十三章 使用动态SQL(一) 动态SQL简介 动态SQL是指在运行时准备并执行的SQL语句。在动态SQL中,准备...

  • 第八章 动态SQL

    动态SQL中的元素介绍 动态SQL有什么作用 MyBatis提供了对SQL语句动态组装的功能 动态SQL中的元素 ...

  • 关于Mybatis的一些问题讨论

    Mybatis动态sql是做什么的?都有哪些动态sql?简述一下动态sql的执行原理 动态sql的用途 Mybat...

网友评论

      本文标题:Mybatis--动态SQL(choose--when--oth

      本文链接:https://www.haomeiwen.com/subject/qmehwrtx.html