queryWrapper实现去重
时间: 2024-01-10 22:03:24 浏览: 134
mybatis plus条件构造器queryWrapper、updateWrapper
可以使用QueryWrapper的select方法结合LambdaQueryWrapper的groupBy方法实现去重。示例代码如下:
```
QueryWrapper<CustomerBodyMetricsEntity> wrapper = new QueryWrapper<>();
wrapper.select("DISTINCT version")
.lambda()
.eq(CustomerBodyMetricsEntity::getCustomerId, customerId)
.ge(CustomerBodyMetricsEntity::getVersion, DateTimeUtil.dateTimeToTimestamp(firstDay))
.le(CustomerBodyMetricsEntity::getVersion, DateTimeUtil.dateTimeToTimestamp(lastDay))
.in(CustomerBodyMetricsEntity::getMetric, list)
.ne(CustomerBodyMetricsEntity::getLabel, 20)
.groupBy(CustomerBodyMetricsEntity::getVersion);
List<CustomerBodyMetricsEntity> list = this.list(wrapper);
```
以上代码中,select方法中传入"DISTINCT version"表示只查询version字段并去重,groupBy方法中传入CustomerBodyMetricsEntity::getVersion表示按照version字段进行分组。
阅读全文