You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

11 lines
852 B

---
description: SQL Server 分页不要把带 ORDER BY 的语句交给 MyBatis-Plus 自动 COUNT
globs: "**/*.{xml,java}"
alwaysApply: false
---
# SQL Server 分页 COUNT
`PaginationInterceptor` 用 JSqlParser 生成 `SELECT COUNT(1) FROM (原 SQL) TOTAL`。JSqlParser 解析不了 `FOR XML`、`OUTER APPLY`、`STRING_AGG` 这类 SQL Server 语法时,不会去掉末尾的 `ORDER BY`。SQL Server 不允许子查询里单独出现 `ORDER BY`,搜索会报 `queryTotal execution error`。
分页查询不要用 `IPage` / `Page` 交给分页插件。单独写一条不带 `ORDER BY`、不带列表字段的 `COUNT`,数据查询自己写 `ORDER BY ... OFFSET #{offset} ROWS FETCH NEXT #{size} ROWS ONLY`。报价单 `queryQuotePageCount` / `queryQuotePageData` 和项目信息 `projectInfoSearchCount` / `projectInfoSearch` 就是这个写法。