数据库报错如下:
Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order’ at line 1
The error may exist in com/biyesheji/order/mapper/OrderMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM order
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order’ at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order’ at line 1] with root cause
然后我复制控制台显示的自动生成的sql语句到数据库中运行,果不其然,也报同样的错
SQL语句:SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM order
下图为数据库报的错误
然后我检查SQL语句,发现生成的表名是order而并不是’order’,少了’'符号
正确的SQL语句应该是SELECT id,sale_money,cost_money,create_time,update_time,customer_id,contract_id FROM ‘order’
这说明mybatis plus没有自动帮其添加’'号,导致其无法识别对应的order表
注意:’ '号并不是单引号,是上侧数字键最左边的~键的英文输入,既 ` 号
解决方法:
在Order对应的POJO类上添加@TableName注解,内容为加上了’ ‘号的表名——等于我们帮mybatis plus加上’'号,这样就能读到order表啦
数据库
ce
error
pt
ep
check
数据
man
SQL
JAVA
cep
al
ec
io
.sql
sq
jav