1. 程式人生 > >org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'xxx' in

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'xxx' in

在使用mybatis的模糊查詢的時候,需要從jsp傳入到controller中一個keyword【String】,在mapper.xml中我是這樣寫的
<select id="fuzzyFind" resultMap="articleResultMap" parameterType="string">
	<![CDATA[
		SELECT * FROM articles WHERE 1=1
	]]>
	<if test="keyword != null">
		<![CDATA[ AND article_title LIKE CONCAT('%','${keyword}','%') ]]>
	</if>
</select>

然後用junit測試的時候,後臺報了org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'keyword' in 'class java.lang.String'這樣的一個錯誤,說keyword這個屬性沒有getter方法,然而我這個keyword不是javabean,沒有必要為其設定getter方法,那怎麼辦呢?我在網上看到了這樣的幾種解決方法:

1. 將string型別換成map型別的,然後將該keyword 放入該map中,不會報錯

2. 在介面中使用@Param(value="xxx") String xxx, 例如:public List<ArticleEntity> fuzzyFind(@Param(value = "keyword") String keyword);  也可以解決問題, 但是我這樣寫還是出現了同樣的錯誤

3. 在配置檔案中直接將keyword換成_parameter,問題解決。

<select id="fuzzyFind" resultMap="articleResultMap" parameterType="string">
	<![CDATA[
		SELECT * FROM articles WHERE 1=1
	]]>
	<if test="_parameter != null">
		<![CDATA[ AND article_title LIKE CONCAT('%','${_parameter}','%') ]]>
	</if>
</select>