mybatis-plus lambda条件构造器
mp框架提供了lambda表达式条件构造器支持;
实例:
/** * 查找薪水大于3500 名字里有“小”的 员工(通过Lambda表达式) * sql: select * from t_employee where salary>3500 and name like '%小%' */ @Test public void selectByQueryWrapperWidthLambda(){ LambdaQueryWrapper<Employee> lambdaQueryWrapper=new QueryWrapper<Employee>().lambda(); // LambdaQueryWrapper<Employee> lambdaQueryWrapper2=new LambdaQueryWrapper(); // LambdaQueryWrapper<Employee> lambdaQueryWrapper3=Wrappers.lambdaQuery(); // queryWrapper.gt("salary",3500).like("name","小"); lambdaQueryWrapper .gt(Employee::getSalary,"3500") .like(Employee::getName,"小"); List<Employee> employeeList = employeeMapper.selectList(lambdaQueryWrapper); System.out.println(employeeList); }
/** * 查找薪水大于3500 名字里有“小”的 员工(通过Lambda表达式) chain * sql: select * from t_employee where salary>3500 and name like '%小%' */ @Test public void selectByQueryWrapperWidthLambda2(){ List<Employee> employeeList = new LambdaQueryChainWrapper<Employee>(employeeMapper) .gt(Employee::getSalary, "3500") .like(Employee::getName, "小") .list(); System.out.println(employeeList); }