异常详情:
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的关键字,原因是数据库表的其中一个属性与关键字同名
四、解决问题
修改数据库中有关键字的属性,改为非关键字,并修改相关代码即可啦
此时就查询成功啦