当前使用版本(必填,否则不予处理)
3.4.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
@Data
@TableName("table_name")
public class User {
@TableId
private Long id;
@TableField("table_field")
private String desc;
// 当使用@TableField注解时 且变量名为数据库关键字时(如desc)得到如下错误sql
select id,table_field as desc from table_name where .....
正确sql 应该为
select id,table_field as “desc” from table_name where ..... (需要加 给变量加 引号(数据库引号打不出来哈哈) ” ” )
重现步骤(如果有就写完整)
1使用 @TableField 注解 2 字段名定义为数据库关键字 3 使用 UserMapper 执行查询
报错信息
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 FROM
Comment From: miemieYaho
自己用注解加上引号
Comment From: 1534196496
写法1( 加不加引号都会报错) @TableField("name") private String desc;
写法2(不会报错) @TableField(" 'desc' ") private String desc;
我说的是写法一,你说的是写法二
Comment From: 1534196496
写法1( 加不加引号都会报错) @TableField("name") private String desc;
写法2(不会报错) @TableField(" 'desc' ") private String desc;
我说的是写法一,你说的是写法二
发自我的iPhone
------------------ 原始邮件 ------------------ 发件人: miemieYaho <notifications@github.com> 发送时间: 2020年12月3日 20:31 收件人: baomidou/mybatis-plus <mybatis-plus@noreply.github.com> 抄送: ll <1534196496@qq.com>, Author <author@noreply.github.com> 主题: 回复:[baomidou/mybatis-plus] 数据库关键字变量结合@TableField注解使用报错 (#3128)
自己用注解加上引号
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Comment From: miemieYaho
https://gitee.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java 133行
Comment From: 1534196496
👍👍👍
发自我的iPhone
------------------ 原始邮件 ------------------ 发件人: miemieYaho <notifications@github.com> 发送时间: 2020年12月3日 21:28 收件人: baomidou/mybatis-plus <mybatis-plus@noreply.github.com> 抄送: ll <1534196496@qq.com>, Author <author@noreply.github.com> 主题: 回复:[baomidou/mybatis-plus] 数据库关键字变量结合@TableField注解使用报错 (#3128)
https://gitee.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java 133行
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.