Mybatis-PageHelper icon indicating copy to clipboard operation
Mybatis-PageHelper copied to clipboard

SqlServer语句中存在中括号会引发异常

Open SealinRepo opened this issue 3 years ago • 0 comments

  • [ √] 我已在 issues 搜索类似问题,并且不存在相同的问题.

异常模板

使用环境

  • PageHelper 版本: 5.3.0
  • 数据库类型和版本: SQL Server 2008
  • JDBC_URL: xxx

SQL 解析错误

分页参数

PageHelper.startPage(1, 10);
xxMapper.select(model);

原 SQL

 select                ID, USER_CODE, USER_NAME, DEP_CODE, AGENT_CODE, ENGLISH_NAME, **[PASSWORD]**, EMAIL, MOBILE, GENDER, AVATAR,     FAIL_COUNT, IS_ACTIVE, CREATE_USER_CODE, CREATE_TIME, MODIFY_USER_CODE, MODIFY_TIME,     REMARK         from T_USER      WHERE  IS_ACTIVE = 1

期望的结果:

select count(0) from (  select                ID, USER_CODE, USER_NAME, DEP_CODE, AGENT_CODE, ENGLISH_NAME, **[PASSWORD]**, EMAIL, MOBILE, GENDER, AVATAR,     FAIL_COUNT, IS_ACTIVE, CREATE_USER_CODE, CREATE_TIME, MODIFY_USER_CODE, MODIFY_TIME,     REMARK         from T_USER      WHERE  IS_ACTIVE = 1  ) tmp_count

完整异常信息

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 [/Users/sealin/Projects/JHJ/auth/dao/target/classes/mappers/UserDao.xml]
### The error may involve com.jhj.auth.dao.UserDao.selectUserList_COUNT
### The error occurred while handling results
### SQL: select count(0) from (  select                ID, USER_CODE, USER_NAME, DEP_CODE, AGENT_CODE, ENGLISH_NAME, [PASSWORD], EMAIL, MOBILE, GENDER, AVATAR,     FAIL_COUNT, IS_ACTIVE, CREATE_USER_CODE, CREATE_TIME, MODIFY_USER_CODE, MODIFY_TIME,     REMARK         from T_USER      WHERE  IS_ACTIVE = 1  ) tmp_count
### Cause: com.github.pagehelper.PageException: 不支持该SQL转换为分页查询!

	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:78)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
	at com.sun.proxy.$Proxy155.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
	at com.sun.proxy.$Proxy174.selectUserList(Unknown Source)
	at com.jhj.auth.service.impl.UserServiceImpl.selectUserList(UserServiceImpl.java:196)

其他类型的错误

功能建议

详细说明,尽可能提供(伪)代码示例。

问题已经查到了, 就是[password]字段存在中括号, 导致第三方插件解析异常, 去掉中括号直接用password作为字段就没这个问题

SealinRepo avatar Dec 27 '21 10:12 SealinRepo