不另外写sql语句,使用mybatis-plus提供的条件构造器Wrapper实现多表连接查询。
ExLambdaQueryWrapper<Student> queryWrapper = new ExLambdaQueryWrapper<>();
queryWrapper.exists("select 1 from course c where c.id = student.id and c.code = '"+code+"'");
以上代码只能实现通过另一张表的字段做条件筛选,最后查询得到的还是Student表中的数据