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

未使用Page分页,但项目中有引入PageHelper插件,却自动判断添加了LIMIT?

Open xiawei520 opened this issue 2 years ago • 1 comments

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

异常模板

使用环境

  • PageHelper 版本: 5.3.2
  • 数据库类型和版本: 5.7
  • JDBC_URL: xxx

SQL 解析错误

分页参数

未使用分页插件Page

    List<CmdbCollectUnknownDTO> list = collectUnknownMapper.list(collectUnknownQuery);
        Integer total = collectUnknownMapper.listCount(collectUnknownQuery);

原 SQL

select * from xxx where xxx = xxx limit 1,10

期望的结果:

select * from xxx where xxx = xxx limit 1,10

完整异常信息

select  nf.*, idc.idc_name idcType_name, dict.dict_note device_type_name,                dict2.id device_class,vm_name,exsi_ip,other_ip,m.id module_id         from cmdb_collect_notfound nf         left join cmdb_idc_manager idc on nf.idcType = idc.id         left join t_cfg_dict dict on nf.device_type = dict.id and dict.col_name='device_type' and ifnull(dict.is_delete, 0) =0         LEFT JOIN t_cfg_dict dict2 ON dict.up_dict = dict2.id AND dict2.col_name='device_class'         left join cmdb_module m on dict.dict_note = m.name and m.is_delete=0         where idc.is_delete =0                                                                         and handle_status = ?                                                                                                                       order by commit_time desc                                 limit 0, 50  LIMIT ?\r\n### 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 'LIMIT 50' at line 29\n; bad SQL grammar []",

其他类型的错误

功能建议

未使用Page分页,DEBUG看代码是从我的入参中判断有PageSize导致判断需要添加分页,实际这个老代码原先已写了分页语句,期望当Page不为空再开启分页,不需要判断Mapper中的参数对象中是否有PageSize字段

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

xiawei520 avatar Nov 23 '23 08:11 xiawei520

通过params配置修改字段名,或者关闭方法参数查询(不影响RowBounds)

abel533 avatar Nov 27 '23 00:11 abel533

pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: false
  params: count=countSql #查资料 supportMethodsArguments: false 配置这个解决了

xiawei520 avatar Apr 07 '24 07:04 xiawei520