Closed kaizhutongxie closed 3 months ago
先查count再分页
先查count再分页
int totalCount = _queryViewFinderService.count(lambdaQueryWrapper);
-----totalCount=38
IPage
更新版本
版本信息:
执行page时报错: 提示
另外提一嘴,可以断点看到生成T-SQL的代码吗?
什么tsql?你把分页插件指定一下数据库类型为sqlserver高的那个版本试试呢
确认
当前程序版本
mybatis-plus-boot-starter 3.4.3.4
问题描述
环境: 主机:MacOS mybatis-plus-boot-starter 3.4.3.4 com.microsoft.sqlserver mssql-jdbc 9.4.0.jre8 docker--->Sqlserver2019dev 在执行这段代码时: @ApiOperation("查询视图列表") @GetMapping("list") public JsonResultObject get(@RequestParam(value = "entityid", required = true) UUID entityId, @RequestParam(name = "name", required = false) String name, @RequestParam(name = "getall", required = false) Boolean getall, @RequestParam(name = "page", required = false) Integer page, @RequestParam(name = "pagesize", required = false) Integer pagesize, @RequestParam(value = "sortby", required = false) String sortby, @RequestParam(value = "sortdirection", required = false) String sortdirection) { if (UUIDUtil.isEmpty(entityId)) { return JNotSpecifiedParams("entityid"); } LambdaQueryWrapper lambdaQueryWrapper = getSortedQueryWrapper(sortby, sortdirection); //sortby, sortdirection
lambdaQueryWrapper.eq(QueryView::getEntityid, entityId);
if (StringUtil.notEmpty(name)) {
lambdaQueryWrapper.like(QueryView::getName, name);
}
if (getall != null && getall) {
return JOk(_queryViewFinderService.list(lambdaQueryWrapper));
} else if (page == null || pagesize == null) {
return JNotSpecifiedParams("page", "pagesize");
}
page = (page <= 0 ? 1 : page);
pagesize = (pagesize <= 0 ? 10 : pagesize);
IPage datas = _queryViewFinderService.page(new Page<>(page, pagesize), lambdaQueryWrapper);
PagedList result = new PagedList<>(datas.getRecords(), page, pagesize, datas.getTotal(), datas.getPages());
这里报错: IPage datas = _queryViewFinderService.page(new Page<>(page, pagesize), lambdaQueryWrapper);
提示:
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Method queryTotal execution error of sql : SELECT COUNT() FROM (SELECT COUNT() FROM (SELECT entityid,[name],[logenabled],[localizedname],[iscustomizable],[authorizationenabled],[entitymask],[duplicateenabled],[workflowenabled],[parententityid],[entitygroups],[createdby],[createdon],[description],[organizationid] FROM dbo.entity ORDER BY createdon DESC) TOTAL) TOTAL 。
这里生成的 SQL 执行失败:
1.2 次SELECT COUNT(*)
2.分页信息丢失了,没有生成分页的 SQL 语句。
详细堆栈日志
No response