Questions
mybatis-plus using PaginationInnerInterceptor paging plugin, when calling the paging query method (****Service.page(new Page(param.getPage(),param.getPageSize()),queryWrapper )) reports the following error:
2022-07-22 17:07:20.699 [TID: N/A] WARN 12444 --- [io-18080-exec-1] c.b.m.e.p.i.PaginationInnerInterceptor : optimize this sql to a count sql has exception, sql:"sql语句略", exception:
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "," ","
at line 1, column 191.
Was expecting one of:
"&"
"::"
";"
"<<"
">>"
"ACTION"
"ACTIVE"
"ALGORITHM"
"ARCHIVE"
"ARRAY"
***略****
reason
The paging plugin will default to sql optimization when processing count, and will throw an exception if optimization fails. The sql that cannot be optimized will be downgraded to the non-optimized count method.
The code summary is as follows.
where Select select = (Select) CCJSqlParserUtil.parse(sql); This line of code reports error:
protected String autoCountSql(IPage<?> page, String sql) {
if (!page.optimizeCountSql()) {
return lowLevelCountSql(sql);
}
try {
Select select = (Select) CCJSqlParserUtil.parse(sql);
**************Optimization Logic*********************
return select.toString();
} catch (JSQLParserException e) {
// Unable to optimize the use of the original SQL
logger.warn("optimize this sql to a count sql has exception, sql:\"" + sql + "\", exception:\n" + e.getCause());
} catch (Exception e) {
logger.warn("optimize this sql to a count sql has error, sql:\"" + sql + "\", exception:\n" + e);
}
return lowLevelCountSql(sql);
}
Solution:
Add the following codes before your codes:
if (!page.optimizeCountSql()) { return lowLevelCountSql(sql); }
just set optimizeCountSql to false, as follows
Page page = new Page(param.getPage(),param.getPageSize()),queryWrapper)
page.setOptimizeCountSql(false);
You can also redefine a class to inherit Page, and set optimizeCountSql default to =false
Read More:
- Mybatis plus paging Plugin and Auto-fill
- [Solved] Mybatis integrates PageHelper and uses sqlserver paging error
- How to Solve Mybatis error: invalid bound statement (not found)
- How to Solve SQL comments error in the mybatis query
- [Solved] Mybatis.generator error: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2
- Mybatis single parameter pass in exception (How to Fix)
- Mybatis-plus: How to Execute Native SQL
- [Solved] Mybatis Error: Could not find resource mybatis-conf.xml
- [Solved] Tk-Mybatis Error: tk.mybatis.mapper.MapperException:
- How to Solve JVM Common Errors: outofmemoryerror & stackoverflowerror
- Mac: How to Solve ERROR launching ‘JD-GUI‘
- How to Solve RAR Files Extract Error with sevenzipjbinding (Multithread Processing)
- How to Solve Tomcat Error: Could not resolve view with name ‘xxx/xxxxxxx‘ in servlet with
- How to Solve Spring Boot Maven Build Error
- How to Solve PageHelper.startPage count Error
- How to Solve IBM MQ Connect Error Code 2035
- [Solved] mybatis plus Insert Error: mybatis plus Error setting null for parameter #1 with JdbcType OTHER
- How to Solve Error: No suitable driver found for
- How to Solve Flick operate Error: not serialized
- How to Solve @Autowired error with Red Wavy Line