xml 中的 > 和 <
符号 | 替换值 |
---|
< | &lt; |
<= | &lt;= |
> | &gt; |
>= | &gt;= |
& | &amp; |
常见的表达式
if
<if test="id != null and id != ''">
user_id = #{id}
</if>
if else 可用 choose...when...otherwise代替
<where>
<choose>
<when test="streetCode != null and streetCode != ''">
bas.street_code = #{streetCode}
</when>
<otherwise>
(bas.street_code like '%' or bas.street_code is NULL)
</otherwise>
</choose>
<if test="statusCodeList != null and statusCodeList.size() > 0">
and bas.status_code in
<foreach collection="statusCodeList" item="item" index="index" open="(" close=")" separator=" , ">
#{item}
</foreach>
</if>
...
</where>
foreach
可直接指定分隔符,非常方便
...
<if test="statusCodes != null and statusCodes.size() > 0">
and bas.status_code in
<foreach collection="statusCodes" item="item" index="index" open="(" close=")" separator=" , ">
#{item}
</foreach>
</if>
...