1.查找操作实现: 1.1 无条件的查找
List<Student> list = studentService.list();
1.2 1.2.1根据多个Id查询
List<Integer> ids = Arrays.asList(202101,202102);
List<Student> list = studentService.listByIds(ids);
1.2.2 单个id:
studentService.getById(202101)
1.3 根据条件查询 1.3.1实现下面的sql语句:
select * from student where student_name ='aaaa';
mybatis-plus实现:
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.eq("student_name",'aaaa');
List<Student> list = studentService.list(wrapper);
1.3.2 多条件的查询(and)
select * from student where student_name="a" and student_id=1;
mybatis-plus实现:
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.eq("student_id",1).eq("student_name","a");
List<Student> list = studentService.list(wrapper);
1.3.3 多条件查询(or)
select * from student where student_naem='a' or student_id=1;
mybatis-plus实现:
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.eq("student_id",1).or().eq("student_name","a");
List<Student> list = studentService.list(wrapper);
1.4 模糊查询(多条件如上)
select * from student where student_naem like 'a'
mybatis-plus实现:
QueryWrapper<Student> wrapper = new QueryWrapper<>();
wrapper.like("student_name","a");
List<Student> list = studentService.list(wrapper);
|