今天写模糊查询时写了如下方法:
1 EntityWrapper wrapper = new EntityWrapper<ExpertEntity>(); 2 wrapper.like("ExpertId", keywords); 3 wrapper.like("ExpertName", keywords); 4 wrapper.like("Email", keywords);
实在看不下去这种字段硬写死的方式,于是引入了LambdaQueryWrapper的写法:
LambdaQueryWrapper<ExpertEntity> wrapper = new LambdaQueryWrapper<ExpertEntity>(); wrapper.like(ExpertEntity::getExpertId, keywords); wrapper.like(ExpertEntity::getExpertName, keywords); wrapper.like(ExpertEntity::getEmail, keywords);
记得要引用3.0版本MP,2.0不支持Lambda写法:
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.1.1</version> </dependency>