There is no getter for property named ‘*’ in 'class java.lang.String
在mapper文件中,使用parameterType="String"
和<if test ="XX !=null">
时会报上述错误。在此先给出解决方法,后续原因供同样有兴趣的朋友交流研究。
解决方法
只需要把<if test ="XX !=null">
中自己传的单参"XX"
(任意自定义参数名称)修改为"_parameter"
即可,也就是<if test ="_parameter !=null">
。其它的内容如 and name = #{name}
不需要更改。或者在mapper.java
中使用@Param
注解。两种方法都可。
原因
直接上图
public static final String PARAMETER_OBJECT_KEY = "_parameter";
public static final String DATABASE_ID_KEY = "_databaseId";
public static Object getValue(Object tree, Map context, Object root, Class resultType)
throws OgnlException
{
OgnlContext ognlContext = (OgnlContext)addDefaultContext(root, context);
Object result = ((Node)tree).getValue(ognlContext, root);
if (resultType != null) {
result = getTypeConverter(context).convertValue(context, root, null, null, result, resultType);
}
return result;
}
{_parameter=00010001, _databaseId=null}
中无法匹配到你的变量名,自然会报错啦~
另外推荐大佬的详细解答:
https://blog.csdn.net/qing_gee/article/details/47122227