mybatisplus-distinct
时间: 2023-11-21 18:54:15 浏览: 346
Mybatis-plus是Mybatis的增强工具,在Mybatis的基础上进行了功能扩展和性能优化。在Mybatis-plus中,可以使用Wrapper来构建查询条件,同时也支持使用distinct语法进行去重查询。具体使用方法可以参考下面的代码示例:
```
List<User> userList = userMapper.selectList(new QueryWrapper<User>().select("distinct name"));
```
这段代码会查询出所有不重复的name字段值。需要注意的是,在使用distinct语法时,需要在select方法中传入要去重的字段名。
相关问题
mybatisplus .distinct
MybatisPlus的.distinct()方法用于在查询中去重复的结果。它可以确保查询结果中的每一行都是唯一的,避免了重复的数据出现。通过使用.distinct()方法,可以在查询中添加DISTINCT关键字,从而使得数据库只返回不重复的记录。这在处理需要排除重复数据的查询结果时非常有用。引用中提到了Mybatis Plus中的.distinct()方法的使用,可能会对你有所帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [django queryset 去重 .distinct()说明](https://download.csdn.net/download/weixin_38560797/12851960)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [MybatisPlus的分页插件自动优化LeftJoin语句导致参数不匹配](https://blog.csdn.net/weixin_51485547/article/details/131462874)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
mybatisplus lambda distinct
To use the distinct keyword in MyBatis Plus with lambda expressions, you can use the following code:
```
LambdaQueryWrapper<Entity> wrapper = Wrappers.lambdaQuery();
wrapper.select(Entity::getColumn1, Entity::getColumn2)
.distinct(true)
.eq(Entity::getColumn3, value);
List<Entity> list = entityMapper.selectList(wrapper);
```
In this example, we create a LambdaQueryWrapper and specify the columns to select using the `select()` method with lambda expressions. We then set the `distinct` flag to true using the `distinct()` method and add any additional query conditions using the various `eq()`, `like()`, or other methods available.
Finally, we execute the query using the `selectList()` method of the entity mapper, which returns a list of entities with distinct values for the specified columns.
阅读全文