mybatis只传入一个String类型的参数时,直接使用
<if test="id != null" >XXXX</if>
的语法会报错:There is no getter for property named 'id' in 'class java.lang.String
此时,无论在接口中定义的参数名称是什么,在 xml文件中都应该使用_parameter来代替参数名,
写成:
<if test="_parameter != null and _parameter != ''">
AND t.id = #{_parameter}
</if>
的形式。
在百度上,很多文章都提到了,也可以使用:
public Object getObjById(@Param("id)String id);
但是我试了一下,会报:'@Param' not applicable to field 的错误,也不知道是不是版本或者引入了错误的@Param标签的缘故,后头找到正确用法了再做补充

本文解决MyBatis使用单个String参数时的常见错误,介绍如何避免There is no getter for property named 'id' in 'class java.lang.String错误,及正确的参数引用方法,包括使用_parameter和@Param注解的注意事项。
6428

被折叠的 条评论
为什么被折叠?



