MyBatis trim 标签四个属性和其作用
属性名 | 作用 |
---|---|
prefix | 添加前缀 |
prefixOverrides | 删除前缀 |
suffix | 添加后缀 |
suffixOverrides | 删除后缀 |
示例
<trim prefix="(" prefixOverrides="and" suffix=")">
<if test="where.commonName!=null">and t.common_name = #{where.commonName}</if>
<if test="where.countryCn!=null">and t.country_cn = #{where.countryCn}</if>
</trim>
在这一段里, 会把多余的 and
前缀删除, 然后把所有 where 条件用 括号包起来,因为有前缀 (
和后缀 )
形成了完整括号