问题
下面是mybatis的xml语句
<select id="userList" resultType="com.sxkj.example.user" parameterType="com.sxkj.example.user">
select * from good
<where>
<if test="userid!=null and userid!=''">
userid=#{userid}
</if>
<if test="state!=null and state='' ">
and state=#{state}
</if>
</where>
order by id desc
</select>
其中 state字段是int类型,如果参数state为0的时候,则无法进入state的条件导致刷选不出来数据。
因为当state的值为0的时候,它的数据类型为Integer,所以这个判断是为false,Mybatis是认为0为’ ’ 的
解决
<if test="state!=null ">
and state=#{state}
</if>