MybatisPlus--3.4 Lambda 查询
作者:互联网
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestLambdaWrapper {
@Autowired
private EmployeeMapper employeeMapper;
/**
* 使用 Lambda 构造器会防止错误书写,因为使用 get 方法的时候不会出现前面写字段名的过程
*/
@Test
public void testLambda1() {
LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeRight(Employee::getLastName, "J");
employeeMapper.selectList(lambdaQueryWrapper).stream()
.forEach(System.out::println);
}
@Test
public void testLambda2() {
LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.likeRight(Employee::getLastName, "J")
.and((lqw) -> lqw.lt(Employee::getAge, 40).or().isNotNull(Employee::getEmail));
employeeMapper.selectList(lambdaQueryWrapper).stream()
.forEach(System.out::println);
}
}
成_蹉_跎
发布了168 篇原创文章 · 获赞 87 · 访问量 9万+
私信
关注
标签:LambdaQueryWrapper,MybatisPlus,lqw,lambdaQueryWrapper,3.4,Employee,employeeMappe 来源: https://blog.csdn.net/cheng_cuo_tuo/article/details/104523090