mybatis-动态sql

概述:

if 判断语句 (但条件分之判断);

choose(when,otherwise) 相当于Java 的case when语句 ,多条件分支判断;

trim(where 、set )辅助语句 用于处理一些sql语句的拼装

foreach 循环语句  在in语句等列举条件常用。

if元素:

if和test属性联合使用。


choose(when,otherwise)元素

trim(where 、set )元素

<where></where>去掉第一个 and

<trim></trim>



 去掉最后一个","号。

foreach元素

能够友好的支持数组和List、set接口集合,对此提供遍历功能。

<foreach item="sex" index="index" collection="sexList" open="(" sepatator="," close=")">

    #{sex}

</foreach>

collection:传递过来的参数;

item:当前循环中的元素;

index:当前元素在集合中的位置下标;

open和close:以什么符号将这些集合包装起来;

separator是各个元素之间的间隔符。

test属性

test相当于判断真假,大多数场景是判断是否为空。

1)判断是否为空 :<if test="A!=null"></if>

2)判断字符串 :<if test="A!='aaa'"></if> 就得版本需要加toString()

bind属性

bind作用是通过OGNL表达式定义一个上下文变量,这样更方便我们适应。




猜你喜欢

转载自blog.csdn.net/qq_15140841/article/details/80719735