Mybatis There is no getter for property named 'XXX' in 'class java.lang.XXX

When using Mybatis query, its parameters can be basic data types or simple data objects such as Integer and String, or complex objects (usually JavaBeans) or map, etc. When using parameters of basic data types, if this The use of parameters is placed in the judgment conditions, as follows:

<select id="getNameList" parameterType="String" resultType="String">
<![CDATA[
SELECT DISTINCT NAME
FROM T_PERSION
WHERE 1=1
]]>
< if test="age!=null">
AND AGE = #{age}
</if>
</select>



may appear:

org.apache.ibatis.reflection.ReflectionException:There is no getter for property named 'XXX' In 'class java.lang.XXX

exception, the direct cause of the problem is that the above parameterType is a basic simple type and there is an if condition for judgment. If there is no subsequent judgment condition, it is:
<select id="getNameList" parameterType="String" resultType=" String">
<![CDATA[
SELECT DISTINCT NAME
FROM T_PERSION
WHERE 1=1
                        AND AGE = #{age}
]]>
</select>

then there is no exception.

For the above exception, it is said on the Internet that the reason for the problem is that Mybatis uses ONGL to parse parameters by default, so it will automatically obtain the incoming variable value in the form of an object tree. There are two solutions:
1. Set the parameter name (the above example is 'age' ') with "_parameter", that is:
<select id="getNameList" parameterType="String" resultType="String">
<![CDATA[
SELECT DISTINCT NAME
FROM T_PERSION
WHERE 1=1
]]>
<if test=" _parameter!=null">
AND AGE = #{_parameter}
</if>
</select>

2. Add the "@Param("parameter name")" mark when defining a method in the interface, for example:
List<String> getNameList( @Param("age")String age);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326495741&siteId=291194637