已解決: 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刪除。



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