mybatis plus in方法使用

    技术2022-07-10  139

    如果是List类型的String,例如:List<String>这种类型的,就直接放值就可以了,本文讲的是当你查询到的是一个list集合如何遍历取值,否则要写sql和接口就显得很麻烦。

    步骤如下:

    //查询到list集合 List<User> userList = userService.selectById(id); //结果集 List<String> resultList = new ArrayList<>(); //遍历集合取值 userList .forEach(item->{ resultList.add(item.getYouNeedId()); }); //条件构造器in上手使用 QueryWrapper<User> qw = new QueryWrapper<>(); qw.in("you_need_id", resultList); //这里有个分页的查询,你也可以不用分页,用mybatisplus里面封装的其他方法 IPage<User> userIPage = userMapper.selectPage(page, qw); //返回查询结果,getRecords也是mybatisplus里面封装的方法 return contractRecordIPage.getRecords();
    Processed: 0.009, SQL: 9