IPage<TicketDemandEntity> page = this.page( new Query<TicketDemandEntity>().getPage(params), new LambdaQueryWrapper<TicketDemandEntity>() .eq(StringUtils.isNotBlank(price), TicketDemandEntity::getPrice, price) .eq(StringUtils.isNotBlank(isMany), TicketDemandEntity::getIsMany, isMany) .eq(StringUtils.isNotBlank(status), TicketDemandEntity::getStatus, status) .eq(StringUtils.isNotBlank(area), TicketDemandEntity::getArea, area) .last("order by status = 1, create_date desc") );帮改一下,先按照status等于1排序,然后按照createDate从近到远排序
时间: 2024-02-14 22:06:31 浏览: 66
spring-boot List转Page的方法步骤
可以将代码改为:
```
IPage<TicketDemandEntity> page = this.page(
new Query<TicketDemandEntity>().getPage(params),
new LambdaQueryWrapper<TicketDemandEntity>()
.eq(StringUtils.isNotBlank(price), TicketDemandEntity::getPrice, price)
.eq(StringUtils.isNotBlank(isMany), TicketDemandEntity::getIsMany, isMany)
.eq(StringUtils.isNotBlank(status), TicketDemandEntity::getStatus, status)
.eq(StringUtils.isNotBlank(area), TicketDemandEntity::getArea, area)
.orderByDesc(TicketDemandEntity::getCreateDate)
.orderByAsc(new QueryWrapper<TicketDemandEntity>().last("FIELD(status, 1, 0)"))
);
```
这样就可以先按照状态从小到大排序(1在前面),再按照创建时间从近到远排序。注意,orderBy方法可以连续调用多次,表示多个排序条件,调用顺序即为排序的优先级。
阅读全文