mybatis-plus报错:SQL语法错误 [错因是实体类有和mysql关键字相同字段]
本帖最后由 ing 于 2022-1-24 17:13 编辑这是报错类的代码,有写new Page<>(startPage, pageSize); 理想不应该会出现这种错误,报错位置已打上断点标记
这个类使用到的mapper
前端
无语的是,我有一个功能相同的实现类却没有报错
完整报错(已忽略报错完整)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.baomidou.mybatisplus.core.toolkit.SetAccessibleAction (file:/C:/Users/admin/.m2/repository/com/baomidou/mybatis-plus-core/3.4.3/mybatis-plus-core-3.4.3.jar) to field java.lang.invoke.SerializedLambda.capturingClass
WARNING: Please consider reporting this to the maintainers of com.baomidou.mybatisplus.core.toolkit.SetAccessibleAction
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
org.springframework.jdbc.BadSqlGrammarException:
### 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 ',rooms,householdsFROM c_building LIMIT 10' at line 1
### The error may exist in com/hstc/dao/mapper/BuildingMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECTid,unit_code,left,rooms,householdsFROM c_building LIMIT ?
### 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 ',rooms,householdsFROM c_building LIMIT 10' 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 ',rooms,householdsFROM c_building LIMIT 10' at line 1
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) 报错是因为实体类有和mysql关键字相同字段
解决方法
```
@TableField("`left`")
private Integer left;
``` 在上面不是已经可以看到sql语句了吗,检查一下是那个字段没有 异常:sql语法错误
截图一大堆。 就是不截完整的数据库结构和sql语句。 看看实体类和表结构啊,设置下吧sql输出出来,你这截了几个无关紧要的图 字段名跟MySQL冲突了吧 关键字做字段名👍 @TableField("`left`") sql异常一般有字段类型错误,关键字错误,关键字重复,分隔符错误
你用的是mybatis-plus封装的查询方法,关键字和分隔符错误可以排除,
具体查下是不是类型错误或者类中的属性和表中是否一一对应。
页:
[1]