最近在练习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}%' 也可

然后成功

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

 

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-11-29
  • 2021-07-04
  • 2021-08-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
相关资源
相似解决方案