2019-08-01 11:35:23.260 ERROR 7152 --- [p-nio-80-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: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '(1 - 1) * 1, 10' at line 6
### The error may exist in file [F:\Test\anima\target\classes\mapper\animaInfoMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: select id, anima_name, season, chapter, anima_link, watch_time, watch_status from anima_info limit (? - 1) * ?, ? ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '(1 - 1) * 1, 10' at line 6 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '(1 - 1) * 1, 10' at line 6] with root cause
あれ,居然出问题了
解决方案
赶紧查找大佬博客资料,好像Mybatis不能执行这种含有运算符的语句,有点坑。
知道问题就好办了,继续查找。
发现了一个标签<bind>,可以使用 OGNL 表达式创建一个变量井将其绑定到上下文中。
继续改改,试试
1 2 3 4 5 6 7 8 9
<selectid="selectAnima"resultMap="BaseResultMap">
<bindname="num"value="(page - 1) * limit" />
select <includerefid="Base_Column_List" /> from anima_info limit #{num} , #{pageSize} </select>