mybatisplus. eq or and
时间: 2023-10-19 18:30:44 浏览: 155
mybatis-plus
5星 · 资源好评率100%
MyBatis Plus provides two methods, `eq` and `and`, for constructing query conditions.
1. `eq`: The `eq` method is used to add an equal condition to the query. It takes two parameters: the column name and the value to compare. It generates a condition like "`column = value`". Here's an example:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("age", 25);
```
2. `and`: The `and` method is used to add multiple conditions to the query. It takes a lambda function as a parameter, where you can specify multiple conditions using methods like `eq`, `like`, etc. It generates conditions combined with an "AND" operator. Here's an example:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.and(wrapper -> wrapper.eq("age", 25).like("name", "John"));
```
In the above example, it adds conditions like "`age = 25`" and "`name LIKE '%John%'`" using the `and` method.
These methods are part of MyBatis Plus's query wrapper (QueryWrapper) class, which makes it easier to construct complex queries without writing SQL statements explicitly.
阅读全文