异常如下
2022-03-16 23:30:34.421 WARN 7452 — [http-nio-8084-exec-1]
c.b.m.e.p.i.PaginationInnerInterceptor : optimize this sql to a
count sql has exception, sql:"SELECT
id,parent_id,user_id,song_id,song_list_id,content,type,like,create_time,update_time,is_delete
FROM comment WHERE is_delete=0AND (song_list_id = ?)", exception:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token:
“like” “LIKE”
at line 1, column 64.Was expecting one of:
2022-03-16 23:30:34.634 ERROR 7452 — [http-nio-8084-exec-1] 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 'like,create_time,update_time,is_delete FROM comment
WHERE is_delete=0AND (’ at line 1 ‘’### The error may exist in
com/liyue/music/dao/CommentMapper.java (best guess) ‘’### The error
may involve defaultParameterMap ‘’### The error occurred while setting
parameters ‘’### SQL: SELECT COUNT(*) FROM (SELECT
id,parent_id,user_id,song_id,song_list_id,content,type,like,create_time,update_time,is_delete
FROM comment WHERE is_delete=0 AND (song_list_id = ?)) TOTAL ‘’###
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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0AND (’ 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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0AND (’ 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
'like,create_time,update_time,is_delete FROM comment WHERE
is_delete=0AND (’ at line 1 at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
~[mysql-connector-java-8.0.22.jar:8.0.22] at
com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)
~[mysql-connector-java-8.0.22.jar:8.0.22]
问题
犯了最基本的错误,用了MySQL关键字做表字段,找到对应的字段修改一下就好了。