关于@NotNull 注解中groups 的使用

简介: 关于@NotNull 注解中groups 的使用

1.实现增删改时,对参数的校验,比如修改或删除时,id不能为空,但其他接口我们又不需要判断id; 以往我们会写在代码里判断;今天新学个注解的新方式:
在NotNull注解里面配置group,需要验证的时候,就在controller参数注解中加上这个groups名称;
group的参数是接口类型,可以自己写一个:

① 如果增删改查父接口是分开写的,需要在controller上写@Validated(参数),例如:

②如果增删改查写成一个接口,则在实现类上加上注解@Validated(参数)即可。必须得加。

相关文章
|
Java Maven
MapStruct - Couldn‘t retrieve @Mapper annotation
MapStruct - Couldn‘t retrieve @Mapper annotation
1869 0
|
4天前
|
XML Java 数据库连接
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
mybatis和mybatiplus中Error attempting to get column ‘xx‘ from result set
28 0
|
4天前
|
SQL XML Java
mybatis元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id *,result*,association报错解决
mybatis元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id *,result*,association报错解决
57 0
|
9月前
|
Java Spring
Spring中@NotEmpty、@NotBlank、@NotNull 区别和使用
Spring中@NotEmpty、@NotBlank、@NotNull 区别和使用
111 0
|
9月前
|
Java Apache Spring
解决required a single bean, but 2 were found问题
背景:springboot整合shiro中自定义Realm时出现 错误描述 Parameter 0 of method getDefaultWebSecurityManager in cn.ken.springboot_shiro.config.ShiroConfig required a single bean, but 2 were foun
|
11月前
|
NoSQL Java Redis
5. 成功解决:Could not autowire. No beans of 'RedisConnectionFactory' type found.
今天建了一个新项目,使用 Spring Boot 整合 Redis 时,IDEA 被提醒“Could not autowire. No beans of 'RedisConnectionFactory' type found. ”错误,意思是不能自动装配“RedisConnectionFactory”。
2254 1
|
Java 编译器
Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.已解决
在创建redisTemplate时,形参列表爆出了如下错误
848 0
Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.已解决
|
Java API Spring
A component required a bean named xxx that could not be found
A component required a bean named xxx that could not be found
A component required a bean named xxx that could not be found
SSM始用 @Autowired(required = false)的一个坑
今天在写东西时候,一个小问题卡了好久,,,我就是要引入两个dao层接口判断,然而一直报500空指针异常,,另一个服务一直找不到,苦恼了很久。才发现原来是注解始用的问题。。貌似是一个@Autowired注解只能引用一个dao。引用多个dao需要多个注解。
106 0
SSM始用 @Autowired(required = false)的一个坑
|
JSON 前端开发 Java
Validated、Valid 、Validator,他们的区别你知道几个
Validated、Valid 、Validator,他们的区别你知道几个
547 0
Validated、Valid 、Validator,他们的区别你知道几个