动态SQL(choose, when, otherwise)

来源:互联网 发布:深圳软件免费培训 编辑:程序博客网 时间:2024/06/06 00:49

概要

1.读者在阅读博客前可以事先阅读MyBatis3.4官方文档
2.本篇博客用于解决在使用MyBatis3.4时可能出现的困惑

choose标签

1.先看一段MyBatis3.4官方文档的例子

<select id="findActiveBlogLike" resultType="Blog">    SELECT * FROM BLOG WHERE state = ‘ACTIVE’    <choose>        <when test="title != null">            AND title like #{title}        </when>        <when test="author != null and author.name != null">            AND author_name like #{author.name}        </when>        <otherwise>            AND featured = 1        </otherwise>    </choose></select>  

2.choose标签在使用时等价于java中的if else

if(...){  ... }else if(...){  ...  }else{  ...}  

参考文档

http://blog.csdn.net/ABCD898989/article/category/6076264
http://blog.csdn.net/abcd898989/article/details/51222452

阅读全文
0 0
原创粉丝点击