使用数据库关键字做字段引起的mybatis或tk.mybatis框架报错

报错信息:

Exception Error:

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 ‘require ) VALUES( 1,‘xx’,‘dfs’,‘sdf’,‘sdfds’,0 )’ 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 ‘require ) VALUES( 1,‘xx’,‘dfs’,‘sdf’,‘sdfds’,0 )’ at line 1

解决方案:

1.mybatis映射文件中写Sql的时候在关键字加转义符号

例如字段:

name     应该写成   `name`
require  应该写成   `require`

2.tk.mybatis增加注解指定字段加转义符号

@Column(name = "`require`")
private Integer require;
@Column(name = "`name`")
private Integer name;
原文地址:https://www.cnblogs.com/javakfz/p/13938199.html