<where>
<if test="sid!=null">
and sid=#{sid}
</if>
</where>
如果正常的这样写,会报错:java.lang.Integer没有sid这个property的getter方法。
这是因为mybatis的这个标签,里面只对对象的属性或者map的内容进行判断。如果是单个的基本类型,并不满足以上条件,那么该如何进行test判断呢??
方法1:
将sid改成_parameter,如下:
<where> <if test="_parameter!=null"> and sid=#{sid} </if>
</where>
这个关键字就是_parameter,不能是别的。
方法2:
将这个基本数据类型放到map中去。
两种方式都可以,自己喜欢哪个选哪个。