mybatisplus contain
时间: 2023-09-10 16:07:24 浏览: 53
MyBatis-Plus (also known as MyBatis+) is an enhanced library that works on top of the MyBatis SQL mapper framework. It provides additional features and utilities to simplify database operations and improve productivity when working with MyBatis.
One of the useful features provided by MyBatis-Plus is the "contain" method. This method allows you to perform a query that checks if a specific value exists within a column.
Here is an example of how you can use the "contain" method in MyBatis-Plus:
```java
// Assuming you have a User entity with a 'name' column
// and a UserService interface with a `selectByName` method
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
@Override
public List<User> getUsersByName(String name) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.like("name", name);
return baseMapper.selectList(queryWrapper);
}
}
```
In this example, the `getUsersByName` method uses the `like` method from the `QueryWrapper` class to perform a query that checks if the name column contains the specified value. The `%` character is automatically added before and after the name value to indicate a partial match.
You can customize the behavior of the `contain` method by using different methods provided by the `QueryWrapper` class, such as `eq` (equals), `ne` (not equals), `lt` (less than), `gt` (greater than), and more.
Remember to configure and integrate MyBatis-Plus properly in your project to use its features effectively.