已解決: mybatis報錯 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'xxx' in 'class java.lang.String'


最近在練習MyBatis時 進行姓名的模糊查詢時候出現

org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'name' in 'class java.lang.String' ### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'name' in 'class java.lang.String'

我的mapper中的select如下

<select id="listAllByName" resultType="edu.ifel.mybatis_test.entitys.Student"> SELECT sno,sname,ssex,sage FROM Student WHERE sname LIKE '%${name}%'
  </select>

測試類中這樣調用 :

    String sname = ""; List<Student> studentList = studentDAO.listAllByName(sname);

 

經過一番查找發現 此處將參數映射為String類型完全正確,但是在映射到<select>中時 '%${name}%' 相當於調用了 sname.name  (即參數.name)

解決方案如下 :

方案一 :   只需將  '%${name}%' 變為 '%${_parameter}%' 即可

方案二 :    將  '%${name}%' 變為 '%${value}%' 也可

然后成功

 


免責聲明!

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



猜您在找 【Mybatis】mybatis查詢報錯org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'areaName' in 'class java.lang.String' Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'zoneId' in 'class java.lang.String' org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String' Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'company' in 'class java.lang.String' Mybatis筆記四:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String' 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 'enterpriseId' in 'class java.lang.String' org.apache.ibatis.reflection.ReflectionException: There is no getter for property named XXX 異常的解決辦法。(親測,一次成功!) #Mybatis org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userId' in 'class java.lang.Integer' Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ItemsCustom' in 'class com.pojo.OrderDetailCustom
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM