Mysql表名使用authorization引发的惨案

文章描述了在MybatisPlus中使用authorization表名时遇到的数据库更新错误,通过修改表名为agent_authorization并应用@TableName注解来解决。
摘要由CSDN通过智能技术生成

Mysql表名使用authorization引发的惨案

复现

使用Mybatis Plus执行更新语句时

public AjaxResult delete(@PathVariable String key) {
    key = key.replace(RequestConstants.PREFIX, "");
    boolean update = authorizationService.lambdaUpdate()
            .eq(Authorization::getAuthKey, key)
            .eq(Authorization::getUserId, getUserId())
            .set(Authorization::getStatus, 2)
            .update();
    return toAjax(update);
}

控制台出现报错

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: UPDATE authorization  SET key_status=?  
 
 WHERE (auth_key = ? AND user_id = ?)
### The error may exist in com/ruoyi/system/mapper/AuthorizationMapper.java (best guess)
### The error may involve com.ruoyi.system.mapper.AuthorizationMapper.update
### The error occurred while executing an update
### Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: UPDATE authorization  SET key_status=?  
 
 WHERE (auth_key = ? AND user_id = ?)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
### Error updating database.  Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: UPDATE authorization  SET key_status=?  
 
 WHERE (auth_key = ? AND user_id = ?)
### The error may exist in com/ruoyi/system/mapper/AuthorizationMapper.java (best guess)
### The error may involve com.ruoyi.system.mapper.AuthorizationMapper.update
### The error occurred while executing an update
### Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: UPDATE authorization  SET key_status=?  
 
 WHERE (auth_key = ? AND user_id = ?)
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
	... 142 common frames omitted
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, Error SQL: UPDATE authorization  SET key_status=?  
 
 WHERE (auth_key = ? AND user_id = ?)
Caused by: net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "authorization" "AUTHORIZATION"
   at line 1, column 8.

Was expecting one of:

提示消息遇到意外标记:"authorization" "AUTHORIZATION

解决

将表名更改
authorization 改为 agent_authorization
Mybatis plus的@TableName

@TableName(value ="agent_authorization")
@Data
public class Authorization implements Serializable {
	...
}

问题修复

我滴妈呀, 再也不敢只用一个单词建表了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值