mybatis的if标签对于单个基本数据类型的参数的判断问题

xiaoxiao2021-02-27  363

<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中去。

两种方式都可以,自己喜欢哪个选哪个。

转载请注明原文地址: https://www.6miu.com/read-4410.html

最新回复(0)