Mybatis問題:There is no getter for property named 'userName' in 'class java.lang.String'
Mybatis遇到的問題
問題:
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userName' in 'class java.lang.String'
分析:
那麼什麼情況下會發生“There is no getter for property named in ‘class
java.lang.String’”錯誤呢?
其實是在這種情況下:
<select id="findByUserName" resultMap="BaseResultMap" parameterType="String">
<if test="userName != null">
and userName = #{userName}
</if>
注意看,是在if test=驗證的時候發生的 “There is no getter for property named in ‘class java.lang.String’”,
而並非是and userName = #{userName} 的時候發生的錯誤。
解決辦法:
<select id="findByUserName" resultMap="BaseResultMap" parameterType="String">
<if test="_parameter != null">
and userName = #{userName}
</if>