mybatis-plus:global-config: db-config:update-strategy: not_null什么意思
时间: 2024-02-22 20:58:51 浏览: 34
`mybatis-plus.global-config.db-config.update-strategy.not-null` 是MyBatis Plus全局配置中的一个属性,用于设置在进行数据库更新操作时,哪些字段不能为null。
具体而言,当 `mybatis-plus.global-config.db-config.update-strategy.not-null` 设置为 `true` 时,MyBatis Plus会在执行更新操作时,检查实体类中的属性值是否为null,如果为null,则会抛出 `MybatisPlusException` 异常,提示该字段不能为null。
例如,假设我们有一个实体类 `User`,其中包含 `id`、`name`、`age` 等属性。如果我们设置 `mybatis-plus.global-config.db-config.update-strategy.not-null` 为 `true`,并且执行如下代码:
```
User user = new User();
user.setId(1L);
user.setName(null);
user.setAge(20);
userMapper.updateById(user);
```
则会抛出 `MybatisPlusException` 异常,提示 `name` 字段不能为null。
总之,通过设置 `mybatis-plus.global-config.db-config.update-strategy.not-null` 属性,我们可以让MyBatis Plus在进行更新操作时,自动检查哪些字段不能为null,避免数据库更新操作出错。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)