Mybatis筆記四:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String'


錯誤異常:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String'

映射器類(Mapper interface)

public interface NarCodeService {
    
    public NarCode getNarCode(String id);

}

Xml映射文件配置(部分)

<select id="getNarCode" parameterType="java.lang.String"
         resultType="narCode">
         select
         <include refid="Base_Column_List"></include>
         from nar_code
         <where>
             <if test="id != null">
                 id=#{id,jdbcType=VARCHAR}
             </if>
         </where>
 </select>

這是Mybatis Xml映射文件配置,當我執行這個映射select語句時報錯:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String'

 解決辦法有兩種:

1.去掉sql語句的if標簽限制

<if test="id != null">  id=#{id,jdbcType=VARCHAR} </if>
改為:
id=#{id,jdbcType=
VARCHAR}

原因:我自己猜測加上if標簽時,id屬性沒有包含在數據類型為String id對象中。
如果去掉if標簽時直接使用這個數據類型為String id對象

2.將parameterType="java.lang.String"參數改為傳一個自定義實體對象或者HashMap來封裝這個id參數
原因:可以在自定義實體對象或者HashMap中找到這個id屬性

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM