mybatis plus eq or
时间: 2023-10-04 20:03:58 浏览: 45
Mybatis Plus中的eq方法是用于生成数据库查询条件的方法,它表示等于。而or方法是用于生成or条件的方法,表示或者。在你提供的示例中,userWrapper.lambda.eq("pwd",pwd).or().eq("phone", phone)表示查询条件为pwd等于指定的pwd值或者phone等于指定的phone值。这个查询条件将会被转换为SQL语句:select * from user where name = ? and ( pwd= ? or phone = ?)。
相关问题
mybatis plus or括号
MyBatis Plus supports the OR condition using the `or` method provided by the `QueryWrapper` class. To use OR conditions with parentheses, you can chain multiple `or` methods together.
Here's an example:
```java
QueryWrapper<Entity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("column1", value1)
.or()
.eq("column2", value2)
.or()
.nested(wrapper -> wrapper.eq("column3", value3).ne("column4", value4));
```
In the above example, `eq` represents the equal condition, `ne` represents the not equal condition, and `nested` is used to create a nested condition with parentheses.
You can adjust the conditions and column names based on your requirements.
mybatis plus or用法
MyBatis-Plus是一个功能强大的MyBatis增强工具包,它提供了更多的查询方法和操作简化功能。在MyBatis-Plus中,使用or进行条件连接可以通过两种方式来实现。
首先,如果需要执行简单的或连接,可以使用or方法直接连接多个条件。比如,使用QueryWrapper来创建查询条件对象,然后使用eq方法设置第一个条件,再调用or方法连接第二个条件。示例如下:
```
QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>()
.eq("attr_id", key)
.or()
.eq("catelog_id", catelogId);
```
这样就可以实现attr_id等于key或者catelog_id等于catelogId的查询条件。
另外,如果需要处理复杂的条件连接,例如存在多个条件并且要设置条件的优先级,可以使用and方法和or方法的Consumer参数重载版本来实现。示例如下:
```
QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>()
.eq("attr_type", "base".equalsIgnoreCase(type) ? 1 : 0)
.and(qr -> qr.eq("attr_id", key).or().like("attr_name", key))
.and(qr -> qr.eq("catelog_id", catelogId));
```
这样就可以实现attr_type等于1或0,并且(attr_id等于key或者attr_name包含key)并且catelog_id等于catelogId的查询条件。
总结起来,MyBatis-Plus提供了简单的or方法和复杂的and方法和or方法的Consumer参数重载版本来实现不同的or用法。具体使用哪种方式取决于你的查询需求和条件连接的复杂程度。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)