There is no getter for property named ‘*‘ in ‘class java.lang.String

There is no getter for property named ‘*’ in 'class java.lang.String

There is no getter for property named '*' in 'class java.lang.String'. This error occurs because mybatis restricts the sql statement with parameterType="String". If you use such a conditional judgment , this error occurs.

  • The following example wrong query
<select id="getRiskMember" resultMap="BaseResultMap" parameterType="String">
	<include refid="selectMember"/>
	<choose>
		<when test="username != null">
			and username = #{username} 
		</when>
		<otherwise>
			and safetylevel > 1
		</otherwise>
	</choose>
 </select>

parameterType="String", this is a must, the parameter type must be string. The corresponding method List getRiskMember(String username) in the mapper class corresponding to the sql;
that is to say, the passed parameter name is username. Under normal circumstances, such a configuration is reasonable.
, you have a corresponding test judgment statement, or if. Then at this time, when the project runs the query statement, it will throw There is no getter for property named 'username' in 'class java.lang.String' error.

So you can just change it to , other places do not need to be changed (that is, and username = #{username} does not need to be changed to and username = #{_parameter}), the modified sql statement is as follows:

<select id="getRiskMember" resultMap="BaseResultMap" parameterType="String">
	<include refid="selectMember"/>
	<choose>
		<when test="_parameter != null">
			and username = #{username} 
		</when>
		<otherwise>
			and safetylevel > 1
		</otherwise>
	</choose>
 </select>

Guess you like

Origin blog.csdn.net/weixin_48453772/article/details/108874400