mybatis plus updateById
时间: 2023-07-27 11:08:19 浏览: 116
MyBatis Plus provides a convenient method called `updateById` for updating records in the database based on the primary key. This method allows you to update a single record by specifying the primary key value and the updated values.
Here's an example of using `updateById` in MyBatis Plus:
```java
// Assuming you have a mapper interface called UserMapper
// Create an instance of the entity class with the updated values
User user = new User();
user.setId(1L); // Assuming 1 is the primary key value
user.setName("New Name");
user.setAge(25);
// Call the updateById method on the mapper interface
userMapper.updateById(user);
```
In this example, we first create an instance of the entity class `User` with the updated values. Then, we call the `updateById` method on the `UserMapper` interface, passing in the updated `User` object.
This method will generate an update SQL statement based on the entity class and update the record in the database with the specified primary key value.
I hope this helps! Let me know if you have any more questions.
阅读全文