当前位置:   article > 正文

There is no getter for property named ‘xxxxx’ in ‘class com.xxx.xx.xx.xxxx‘”,_there is no getter for property named 'student_id'

there is no getter for property named 'student_id' in 'class com.jeethink.pr

原文链接:https://www.longkui.site/program/java/getter/5082/

0.背景
SpringMVC架构,使用mybatis执行insert语句,然后开始报错:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘xxxxx’ in ‘class com.xxx.xxx.api.xxxx’”,

mapper层的写法:

void insertStudent(Student student);
xml层的写法:

insert into stu(id,name) values (#{id},#{name}) 然后就开始报上面的错误了。

1.问题原因及解法方法
实体类缺失getter/setter 方法。 解决办法,加入getter/setter方法
实体类名与数据库类名不符。这个一般遇不到,而且可以不一定要对应。
实体类名与 xml 中的 property 名不符, xml 中 column 名与 property 名不符。 解决办法: 这个如果你要做一一对应的话就写成一样的,要不然自己写参数对应也行。
编写 sql 语句不要多空格少逗号之类的,不要写错少些字母。解法办法:请仔细检查sql语句。
最后,就是我实际遇到的,mapper层和xml层写错了。

上面的mapper层代码应该改成下面这样:

void insertStudent(@Param(“student”) Student student);
xml层应该改成下面这样:

insert into stu(id,name) values (#{student.id},#{student.name}) PS: 不要过度依赖代码生成器,有的代码自己写两遍才知道问题所在。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/71861
推荐阅读
相关标签
  

闽ICP备14008679号