springboot使用mybatis-plus的继承的方法查询数据库报错2022-04-13 18:22:59.972 ERROR 3348 --- [nio-8080-exec-2] o.a.c.

异常详情:

2022-04-13 18:22:59.972 ERROR 3348 — [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 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 ‘FROM device’ at line 1
-### The error may exist in com/management/deviceManage/mapper/DeviceMapper.java (best guess)
-### The error may involve defaultParameterMap
-### The error occurred while setting parameters
-### SQL: SELECT id,room_id,device_name,device_type,purchace_date,device_guarantee,device_describe,device_state,character FROM device
-### 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 ‘FROM device’ 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 ‘FROM device’ at line 1] with root 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 ‘FROM device’ at line 1
![在这里插入图片描述](https://img-blog.csdnimg.cn/6825f2c92ae0446e8108307330da31f8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5piO5piO5Zyo5bmy5Zib,size_20,color_FFFFFF,t_70,g_se,x_16在这里插入图片描述

出错接口

在这里插入图片描述

解决办法:

一、配置mybatis日志工具,看一下出错的sql语句

在yml配置文件中加入如下代码

logging:
  level:
    root: info
    com.management.deviceManage.mapper.*: debug
二、此时再运行一下代码即可打印出sql语句
2022-04-13 18:43:21.181 DEBUG 9952 --- [nio-8080-exec-1] c.m.d.mapper.DeviceMapper.selectList     : ==>  Preparing: SELECT id,room_id,device_name,device_type,purchace_date,device_guarantee,device_describe,device_state,character FROM device
2022-04-13 18:43:21.203 DEBUG 9952 --- [nio-8080-exec-1] c.m.d.mapper.DeviceMapper.selectList     : ==> Parameters: 

在这里插入图片描述

三、找出异常原因:

可以看到sql语句查询的属性中有mysql的关键字,原因是数据库表的其中一个属性与关键字同名
在这里插入图片描述

四、解决问题

修改数据库中有关键字的属性,改为非关键字,并修改相关代码即可啦
在这里插入图片描述
此时就查询成功啦
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值