MyBatis + MyBatis Plus + MySQL——查询语句中字段名为MySQL关键字问题解决方案
生活随笔
收集整理的這篇文章主要介紹了
MyBatis + MyBatis Plus + MySQL——查询语句中字段名为MySQL关键字问题解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題描述
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc,username,create_time,update_time FROM test WHERE id=1' at line 1 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc,username,create_time,update_time FROM test WHERE id=1' at line 1] with root causecom.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'desc,username,create_time,update_time FROM test WHERE id=1' at line 1問題分析
數據庫表中將SQL關鍵字作為字段名時,在查詢的時候MySQL無法進行正常查詢。
Maven
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.2</version></dependency><!--MyBatis-Plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.3.1.tmp</version></dependency>解決方案
XML
錯誤:DELETE = #{delete}正確:`DELETE` = #{delete}注解?
在@TableField注解中加入反引號“ ` ”
@TableField("`function`")private String function;參考文章
https://blog.csdn.net/yq1220/article/details/99606067
https://bbs.csdn.net/topics/392502000
https://blog.csdn.net/qq_34285939/article/details/86605105
https://blog.csdn.net/u012031380/article/details/53940739
總結
以上是生活随笔為你收集整理的MyBatis + MyBatis Plus + MySQL——查询语句中字段名为MySQL关键字问题解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浙江理工大学信息学院本科生创新项目总结报
- 下一篇: Intellij IDEA + Mave