kution 发表于 2016-11-26 10:53:38

Mybatis 简单的判断语法

<!-- 多选
<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>
-->
<!-- 循环
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
-->
<!-- trim 在这的作用是去掉所包含的前缀AND 或者OR 其他属性(suffixOverrides去掉后缀,加上前缀prefix,加上后缀suffix)
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="state != null">
state = #{state}
</if>
<if test="title != null">
AND title like #{title}
</if>
<if test="author != null and author.name != null">
AND author_name like #{author.name}
</if>      
</trim>
-->
页: [1]
查看完整版本: Mybatis 简单的判断语法