Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryWrapper orderByDesc排序不生效 #5924

Open
Witnin opened this issue Feb 28, 2024 · 2 comments
Open

queryWrapper orderByDesc排序不生效 #5924

Witnin opened this issue Feb 28, 2024 · 2 comments

Comments

@Witnin
Copy link

Witnin commented Feb 28, 2024

版本号:3.6.2
前端版本:vue3版
问题描述: queryWrapper orderByDesc排序不生效
截图&代码:

image
image
image

@citynook
Copy link

@Witnin 用 initQueryWrapper用 req 的参数创建的QueryWrapper,已经根据传递进来的参数生成了排序规则,用代码添加新的排序规则是无效的。

要想自定义排序,可以自己创建 LambdaQueryWrapper,示例如下,查询使用了 like,不是默认的 eq:

	@Operation(summary = "度量单位-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<SysUom>> queryPageList(SysUom sysUom,
											  @RequestParam(name="uomCategory", defaultValue = "") String uomCategory,
											  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
											  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
											   @RequestParam(name="uomName", defaultValue="") String uomName,
											   @RequestParam(name="uomCode", defaultValue="") String uomCode,
											  HttpServletRequest req) {
		Result<IPage<SysUom>> result = new Result<IPage<SysUom>>();
		LambdaQueryWrapper<SysUom> queryWrapper = new LambdaQueryWrapper<SysUom>();
		if (uomCategory.length() > 0) {
			queryWrapper.eq(SysUom::getUomCategory, uomCategory);
		}
		if (uomName.length() > 0) {
			queryWrapper.like(SysUom::getUomName, uomName);
		}
		if (uomCode.length() > 0) {
			queryWrapper.like(SysUom::getUomCode, uomCode);
		}
		queryWrapper.orderByAsc(SysUom::getUomCategory);
		queryWrapper.orderByAsc(SysUom::getSortNo);

		Page<SysUom> page = new Page<SysUom>(pageNo, pageSize);
		IPage<SysUom> pageList = this.sysUomService.page(page, queryWrapper);
		result.setSuccess(true);
		result.setResult(pageList);
		return result;
	}

@hejie3225
Copy link

上面的方法也可以,就是不能使用initQueryWrapper方法了;也可以采用下面的方案配合initQueryWrapper来使用;
在initQueryWrapper之前增加如下代码用来替换默认的按照时间排序。
Map<String, String[]> map =new HashMap(req.getParameterMap());
map.put("column",new String[]{"address_is_top"});
map.put("order",new String[]{"desc"});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants