MyBatis-Plus allEq()的用法
首先创建一个数据库表,如下图所示:
然后创建一个Spring Boot项目,pom.xml和配置如下:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://.kaven.mybatisplus.entity.User;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import java.util.HashMap;import java.util.List;import java.util.Map;@RunWith(SpringRunner.class)@SpringBootTestpublic class UserMapperAllEqTest { @Autowired private UserMapper userMapper; @Test public void selectList(){ QueryWrapper<User> userQueryWrapper = Wrappers.query(); Map<String , Object> map = new HashMap<>(); map.put("username" , null); map.put("age" , 22); map.put("password" , "1"); userQueryWrapper.allEq((k , v) -> !k.equals("password") , map , false); List<User> userList = userMapper.selectList(userQueryWrapper); }}看上面代码很容易知道,filter参数我传了一个lambda表达式,意思是key为password的键值对在查询时会被忽略掉。
结果如下:
结果很显然也是正确的。
boolean condition参数的作用我在另一篇博客有介绍过,这里就不再赘述了。
MyBatis-Plus 条件构造器之condition参数
到此这篇关于MyBatis-Plus allEq()的用法详解的文章就介绍到这了,更多相关MyBatis-Plus allEq()内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!