SpringBoot整合MyBatis报错org.springframework.jdbc.BadSqlGrammarException:Column count doesn‘t match valu

报错信息

org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLException: Column count doesn't match value count at row 1
### The error may exist in file [D:\code\community\target\classes\mapper\user-mapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into user (          id,username, password, salt, email, type, status, activation_code, header_url, create_time      )         values (?,?,?,?,?,         ?,?,?,?)
### Cause: java.sql.SQLException: Column count doesn't match value count at row 1
; bad SQL grammar []; nested exception is java.sql.SQLException: Column count doesn't match value count at row 1

写得很清楚了,我写了个Bad SQL grammar

原因

检查了一下有两处错误:
SpringBoot整合MyBatis报错org.springframework.jdbc.BadSqlGrammarException:Column count doesn‘t match valu_第1张图片
1.后面应该加上parameterType="User" keyProperty="id"
前一个是因为方法返回的User是自定义的类,MyBatis不能自动识别,需要点明一下。简单类MyBatis可以自动识别(刚刚试了一下这个不写也不会出错)
后一个是,因为insertFields里没有写id,需要告诉MyBatiis自动填入的主键叫啥名
(额,这两个不写好像也不会出错,但是为 了防止以后出现莫名其妙的bug还是写上吧)

2.手滑写错了,应该是insertFields

还是要不看老师的代码自己敲一遍,不然都不知道怎么会有这么多奇怪的手滑写错和bug。。。
SpringBoot整合MyBatis报错org.springframework.jdbc.BadSqlGrammarException:Column count doesn‘t match valu_第2张图片
红框处应该是表格属性名,#{}里是属性名

你可能感兴趣的:(报错及处理,spring,boot)