Mybatis plus queryupdate wrapper 怎么用? 举列说明
时间: 2023-06-09 19:08:29 浏览: 53
好的,关于Mybatis plus queryupdate wrapper 的使用方法,可以先创建一个 UpdateWrapper 对象,然后设置更新条件和更新内容,最后调用 Mybatis plus 提供的 update 方法实现更新操作。具体操作步骤如下:
1. 首先引入 Mybatis plus 的依赖,如下:
```
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.7.1</version>
</dependency>
```
2. 然后创建一个 UpdateWrapper 对象,如下:
```java
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
```
3. 接着可以设置更新条件,如下:
```java
updateWrapper.lambda().eq(User::getId, 1);
```
这表示更新条件为 id = 1 的记录。
4. 然后可以设置更新内容,如下:
```java
User user = new User();
user.setName("Tom");
user.setAge(20);
updateWrapper.lambda().set(User::getAge, user.getAge()).set(User::getName, user.getName());
```
这表示将 age 和 name 字段更新为指定值。
5. 最后调用 Mybatis plus 提供的 update 方法实现更新操作,如下:
```java
userMapper.update(user, updateWrapper);
```
这表示更新 user 表中满足条件的记录。
以上就是 Mybatis plus queryupdate wrapper 的使用方法,希望能够帮到您。