### The error may involve defaultParameterMap ### The error occurred while setting parameters

Posted brilliantZC

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了### The error may involve defaultParameterMap ### The error occurred while setting parameters相关的知识,希望对你有一定的参考价值。

今天遇到一个错误,运行RankDao.selectById(id)直接给我报错,很不理解

错误信息:

2021-09-22 10:40:58.824 ERROR 8364 --- [nio-8888-exec-4] 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 'rank WHERE id=1' at line 1
### The error may exist in com/brilliantZC/music/dao/MusicRankDao.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=?
### 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 'rank WHERE id=1' 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 'rank WHERE id=1' at line 1] with root cause

一开始各种百度了各种方法,有说

  1. 创建的表中列的值小于实际值而报错
  2. Controllor 层引入的 Service 接口上面忘记写 @Resource 或 @Autowired 注解
  3. Controllor 层调用的方法是 private 私有的,导致分发失败
  4. 检查Mapper接口代码是否符合规范(用的Mybatis-plus自动忽略)

都试过一遍还是不行,于是我拿着错误的sql语句执行

SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1

依然报错

music> SELECT id,song_list_id,consumer_id,score FROM rank WHERE id=1
[2021-09-22 10:55:58] [42000][1064] 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 'rank WHERE id=1' at line 1

然后我就迷茫了,接着我把查询语句去掉依然报错

SELECT id,song_list_id,consumer_id,score FROM rank

接着百度,看到因为rank是关键字,不能直接当做非关键字用,需要加上``来使用。换上后可执行了

SELECT id,song_list_id,consumer_id,score FROM `rank`

然后我就修改了表名,错误解决!!!

以上是关于### The error may involve defaultParameterMap ### The error occurred while setting parameters的主要内容,如果未能解决你的问题,请参考以下文章

### The error may involve defaultParameterMap ### The error occurred while setting parameters

### The error may involve defaultParameterMap ### The error occurred while setting parameters

mybatis报错:The error may exist in xxxxMapper.xml

mybatis报错:The error may exist in xxxxMapper.xml

mybatis报错:The error may exist in xxxxMapper.xml

mybatis的小坑 ### The error may exist in com/vector/dao/*Mapper.xml