在MyBatis-Plus中,查询去重(使用DISTINCT关键字)是一个常见的需求。你可以通过多种方式来实现这一需求。以下是几种常见的去重查询方法: 使用QueryWrapper或LambdaQueryWrapper的select方法: 你可以通过QueryWrapper或LambdaQueryWrapper的select方法来指定要查询的列,并在列名前添加DISTINCT关键字来实现去重。 java // 使用...
mybatis-plus的distinct用法 在MyBatis-Plus中,可以使用wrapper对象实现distinct查询。 具体用法如下所示: ``` QueryWrapper<User> wrapper = new QueryWrapper<>(); wrapper.select("DISTINCT name").eq("age", 18); List<User> userList = userMapper.selectList(wrapper); ``` 上述代码中,使用`select`方法...
QueryWrapperqueryWrapper = new QueryWrapper<>(); queryWrapper.select("DISTINCT no,name").orderByAsc("no"); return mapper.selectList(queryWrapper); distinct去重复查询的使用 查询的结果有时会有重复值,需要去除重复值,在sql查询中使用distinct关键字很方便的达到效果。例如: SELECT distinct ckbm,qy,hwbm FR...
在MyBatis Plus中,可以使用QueryWrapper或LambdaQueryWrapper来构建查询条件,然后使用selectDistinct方法来去重查询结果。 示例代码如下: QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.selectDistinct("name", "age").eq("status", 1); List<User> userList = userMapper.selectList(queryWrapper...
复制代码 在查询时,可以使用selectList()方法来查询数据,并且通过distinct方法去重: List<User> userList = userMapper.selectList(new QueryWrapper<User>() .select("distinct id, name")); 复制代码 这样就可以实现对指定字段进行去重操作。 0 赞 0 踩...
然后我们编写Service类,用来调用Mapper接口中的方法,并返回查询结果。 // UserService.java@ServicepublicclassUserService{@AutowiredprivateUserMapperuserMapper;publicList<String>getDistinctNames(){returnuserMapper.selectDistinctNames();}} 1. 2. 3.
Mybatis Plus QueryWrapper的lambda用起来感觉挺爽的,有点JPA的感觉,也不需要拼很多字符串,可以利用IDE的代码检查功能,总之好处多多,停不下来。最近遇到一个问题,需要对SQL查询的结果做去重处理,自然想到了使用 distinct。 对于复杂的SQL语句,一般使用自定义XML的方式,但是这么个小问题,XML能不写就尽量不写了。查看了...
Mybatis plus实现Distinct去重功能 不啰嗦,上菜 QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.select("DISTINCT no,name").orderByAsc("no"); return mapper.selectList(queryWrapper); 123 1. 2. 3. 4. PS: 顺便一提,指明查询出后的结果输出类型,可以参考如下: ...
mybatis plus 一对多查询 public interface HarmBehavorHardwareParaMapper extends CommonMapper<HarmBehavorHardwarePara> { @Select("select distinct rc.vehicle_id,rc.node_id,rc.project_id,hi.hardware_id,hi.hardware_id as 'hardware_ids',hi.hardware_name,hi.hardware_code,ef.function_id, ef.function_...
在MyBatis Plus中,可以使用distinct方法来实现去重的功能。distinct方法可以用于QueryWrapper或LambdaQueryWrapper对象上。 使用示例: // 使用QueryWrapper的distinct方法 QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.select("id", "name").distinct(true).eq("age", 18); List<User> user...