控制台报错如下所示:
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'createBy' in 'class com.smbms.pojo.User'
### The error may exist in com/smbms/dao/user/UserMapper.xml
### The error may involve com.smbms.dao.user.UserMapper.addUser-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO `smbms_user`(`userCode`,`userName`,`userPassword`,`gender` ,`birthday`,`phone`,`address`,`userRole`,`createBy`,`creationDate`) VALUES(?,?,?,?,?,?,?,?,?,?);
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'createBy' in 'class com.smbms.pojo.User'
首先对错误提示进行分析,可以看到错误中提示:There is no getter for property named 'createBy' in 'class com.smbms.pojo.User'
,这个提示说的是createBy
这个字段是没有的,或者没有进行get或set封装的,所以我们去到它的实体类User
找到对应的属性名,然后将错误的属性名,找出来,可以看到我这边正确的属性应该是cretedBy
,看出差异后修改xml SQL映射文件中的对应字段,这样问题就完美解决了。
User实体类:
SQL映射文件中的代码错误位置:
修改后的SQL映射文件内容:
运行成功啦: