首先举个例子
Test类:
mapper:
FtValidatecodeDo selectTest(@Param("state") Integer state);
xml文件:
<select id="selectTest" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ft_validatecode
where 1=1
<if test="state != null and state !='' ">
and code_id = '15601117075'
</if>
limit 1
</select>
1.上面传输的是一个Integer类型的state,我们会发现
当state为0的时候,<if test="state != null and state !='' "> 结果为false。
当state为不为0的时候,<if test="state != null and state !=' ' "> 结果为true。
2.如果把 and state !=' '去掉的话就可以正常判断都为true,这是因为and state !=' '会默认把state当作字符串,具体原因我也不是很清楚。