1、IF 验证
IF验证通常是验证字符串是否为空,或者处理当等于某个值时。
写法: <if test="answerListSize > 0"></if> 当值>0时
<if test="answerListSize != null and answerListSize != '' "></if> 当值不为空时
<if test = ‘ answerListSize == "1" ’></if> 当值等于1时
2、IN写法
WHERE test IN
<foreach item="item" index="index" collection="answerList" open="(" separator="," close=")">
#{item}
</foreach>
answerList是传进来的数组,可用Map或者Bean为入参。
3、处理<符号
<在Mybatis的XML里面是通译符,直接使用会报错。
<![CDATA[
AND qao.qa_id <> qa_old_id
]]>
使用<![CDATA[ ]]> 包起来
4、include
<include refid="and_where_clause"/>
此语法可以直接将and_where_clause中的语句拼接在你sql语句中,根据你放的位置
<sql id="and_where_clause"><sql>