mybatis的if标签对于单个基本数据类型的参数的判断问题
尊重原创: http://blog.csdn.net/little_newbee/article/details/71171491
<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中去。

浙公网安备 33010602011771号