Mybatis框架-23:动态SQL——if标签、where标签、trim标签、choose标签
2019-06-09 16:55
639 查看
if标签
从下面这个查询语句我们可以很容易的看出,if标签其实是做判断使用的,当满足条件的时候执行对应的语句
[code]<select id="getCustomerByNameAndPossition" resultType="com.ctbu.domain.Customer"> select * from `customer` <where> <if test="cust_name !=null and cust_name !=''"> cust_name=#{cust_name} </if> <if test="cust_profession !=null and cust_profession !=''"> and cust_profession=#{cust_profession} </if> </where> </select>
where标签
可以自动生成sql语句中的where以及删除where之后的第一个and
trim标签
[code]prefixOverrides="and" :前缀覆盖,覆盖第一个条件之前的相应内容 suffixOverrides="and" :后缀覆盖,覆盖最后一个条件之后的相应内容 prefix="" :前缀,在第一个条件之前添加的内容 suffix="":后缀,在最后一个条件之后添加的内容
[code]<trim prefixOverrides="and" suffixOverrides="and"> <if test="cust_name !=null and cust_name !=''"> cust_name=#{cust_name} </if> <if test="cust_profession !=null and cust_profession !=''"> and cust_profession=#{cust_profession} </if> </trim>
choose标签
判断当前条件如果成立,则不会判断后面的是否成立,如果前面的都不成立,则执行otherwise中的内容
[code]<select id="getCustomerByNameAndPossition" resultType="com.ctbu.domain.Customer"> select * from `customer` <where> <choose> <when test="cust_name != null"> cust_name=#{cust_name} </when> <when test="cust_profession != null"> cust_profession=#{cust_profession} </when> <otherwise> cust_name='李白' </otherwise> </choose> </where> </select>
相关文章推荐
- MyBatis代码实例系列-06:Mybatis动态SQL标签(一)---if、where、set、trim、choose
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach标签的使用
- mybatis框架用高级版1动态sql片段 where字句 和 trim 标签 分别 对单表进行增改查处理
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- mybatis-动态sql-if,choose,when,otherwis,trim,where,set,foreach,test,bind
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用
- Mybatis动态SQL——if、choose、where、set、trim、foreach标记实例
- Mybatis动态SQL之if、choose、where、set、trim、foreach标记实例详解
- Mybatis动态SQL——if,where,trim,choose,set.foreach的用法
- 【Mybatis学习笔记】06 动态sql if/choose/where
- MyBatis动态语句 (二)if set choose where foreach trim
- MyBatis动态SQL之一使用 if 标签和 choose标签
- SSM框架day02-MyBatis——036 动态SQL-where、037 动态SQL-choose、038 动态SQL-foreach数组、039 动态SQL-foreachList
- mybatis的动态SQL(三)where、set、trim标签的使用
- mybatis中动态sql标签之if trim
- MyBatis动态SQL之一使用 if 标签和 choose标签
- MyBatis学习笔记-07.MyBatis动态Sql语句if、where、trim、set
- Mybatis的动态sql----where,trim,set,foreach
- mybatis动态sql中的trim标签的使用