choose-when-otherwise
只能满足一个when 中的条件,互斥的条件,不能同时存在
mapper.xml
<select id="selectstateByTitleOrstyle" parameterType="Blog" resultMap="blogResultMap" >
select * from blog where state = "1"
<choose>
<when test="title != null and title != ''">
and title like #{title}
</when>
<when test="style != null and style != ''">
and style = #{style}
</when>
<otherwise>
and featured = "1"
</otherwise>
</choose>
</select>
 实际应用:
 <choose>
             <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                 ORDER BY ${page.orderBy}
             </when>
             <otherwise>
                 ORDER BY a.update_date DESC
             </otherwise>
         </choose>

7 . 动态sql-choose的更多相关文章

  1. mybatis 详解(五)------动态SQL

    前面几篇博客我们通过实例讲解了用mybatis对一张表进行的CRUD操作,但是我们发现写的 SQL 语句都比较简单,如果有比较复杂的业务,我们需要写复杂的 SQL 语句,往往需要拼接,而拼接 SQL ...

  2. 【转载】 mybatis入门系列四之动态SQL

    mybatis 详解(五)------动态SQL 目录 1.动态SQL:if 语句 2.动态SQL:if+where 语句 3.动态SQL:if+set 语句 4.动态SQL:choose(when, ...

  3. mybatis 详解------动态SQL

    mybatis 详解------动态SQL   目录 1.动态SQL:if 语句 2.动态SQL:if+where 语句 3.动态SQL:if+set 语句 4.动态SQL:choose(when,o ...

  4. mybatis 动态SQL .2

    目录 1.动态SQL:if 语句 2.动态SQL:if+where 语句 3.动态SQL:if+set 语句 4.动态SQL:choose(when,otherwise) 语句 5.动态SQL:tri ...

  5. MyBatis动态SQL之一使用 if 标签和 choose标签

    bootstrap react https://segmentfault.com/a/1190000010383464 xml 中 < 转义 to thi tha <if test=&qu ...

  6. Mybatis动态SQL——if,where,trim,choose,set.foreach的用法

    知识点:主要介绍mybatis中,动态sql中的if,where,trim,set,foreach的用法 自学谷粒学院mybatis学习视频,参考mybatis官方文档 java包:log4j.jar ...

  7. mybatis 基础(二) 动态sql 关于where if / where choose when otherwise

    个人理解: where if就相当于正常的java中的if 语句,如果有多个条件组合判断的话用 and, or连接 而where choose when otherwise choose就好像是swi ...

  8. MyBatis从入门到精通(第4章):MyBatis动态SQL【if、choose 和 where、set、trim】

    (第4章):MyBatis动态SQL[if.choose 和 where.set.trim] MyBatis 的强大特性之一便是它的动态 SQL.MyBatis 3.4.6版本采用了功能强大的OGNL ...

  9. MyBatis4:动态SQL

    什么是动态SQL MyBatis的一个强大特性之一通常是它的动态SQL能力.如果你有使用JDBC或其他相似框架的经验,你就明白条件串联SQL字符串在一起是多么地痛苦,确保不能忘了空格或者在列表的最后的 ...

  10. mybatis 动态sql表达式相关应用

    一.mybatis 表达式简介 对于mybatis3 ,提供了一种动态sql的方式.通过动态sql我们可以直接在mybatis 的xm映射文件中直接通过条件判断的方式进行查询添加的拼接.mybatis ...

随机推荐

  1. FMX 模态窗体

    FMX 模态窗体 dlg := TForm2.Create(nil);  dlg.ShowModal(procedure(ModalResult: TModalResult)  begin       ...

  2. eclipse中的TODO和FIXME

    最近使用eclipse开发代码时,公司要求按他们制定代码规范编写代码,其他都还好,因为基本都养成良好习惯了,但TODO和FIXME就有点陌生,查了一下资料,发现笔者寡闻了,果然学海无涯,好了,下边解释 ...

  3. JS中,根据div数值判断弹出窗口

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 用JS,求斐波那契数列第n项的值

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. JSP 按钮点击,onclick事件中的AJAX不执行可能的原因

    <button onclick="deleteAccount()"  >删除</button> 缺少了 type="button" &l ...

  6. bzoj 2653 middle(主席树)

    题面:https://vjudge.net/problem/HYSBZ-2653 博客:https://blog.csdn.net/litble/article/details/78984846 这个 ...

  7. ReactNative http网络通讯

    安装 fetch npm install whatwg-fetch --save 1.fetch的Get方式通讯 async sendGet(){ let response = await fetch ...

  8. Struts2框架05 result标签的类型、拦截器

    1 result标签是干什么的 就是结果,服务器处理完返回给浏览器的结果:是一个输出结果数据的组件 2 什么时候需要指定result标签的类型 把要输出的结果数据按照我们指定的数据类型进行处理 3 常 ...

  9. google浏览器:Ignored call to 'confirm()'. The document is sandboxed, and the 'allow-modals' keyword is not set

    最近做一个功能,测试环境测试没问题,google浏览器测试也没问题,结果上生产发现google浏览器竟然用不了.查看控制台发现控制台报错: Ignored call to 'confirm()'. T ...

  10. iOS 判断设备是否越狱了

    #import "PrisonBreakCheck.h" @implementation PrisonBreakCheck /** * 判断iPhone是否越狱了 */ +(BOO ...