今天发现个很奇葩的bug,使用PageHelp进行分页时候,表名如果是数字开头,那么就会出现以下使用PageHelper进行分页时候,数字开头的表,在select count(0)时候,会报错 不支持该SQL转换为分页查询
报错内容如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: com.github.pagehelper.PageException: 不支持该SQL转换为分页查询!
### The error may exist in file [E:\WorkSpace\RuiShu\target\classes\mapper\TbFormDataList.xml]
### The error may involve com.cric.ruishu.mapper.dataList.TbFormListDataMapper.searchDataOr_COUNT
### The error occurred while handling results
### SQL: select count(0) from (SELECT * from [1] where 1=1) tmp_count
### Cause: com.github.pagehelper.PageException: 不支持该SQL转换为分页查询!
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
at com.sun.proxy.$Proxy120.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:158)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:76)
但是 select count(0) from (SELECT * from [1] where 1=1) tmp_count明明在数据库里可以执行啊。
我于是干脆自写一个count方法,写了个SELECT count(0) from [1] where 1=1
结果还是一样的报错。
找了半天,初步怀疑是SqlServerParser.convertToPageSql的 转换为分页语句 这个方法中的
CCJSqlParserUtil.parse(sql)
出错,但是具体什么原因,尚不清楚。
最后实在是找不到原因,干脆给所有表加英文前缀。
没找到bug原因,只能绕过去了,唉。