javax.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not redefine the parameter constraint configuration
@Validated注解接口
Validated(Default.class)
public interface HelloService {
Object hello(@NotNull @Min(10) Integer id, @NotNull String name);
}
// 实现类如下
@Slf4j
@Service
public class HelloServiceImpl implements HelloService {
@Override
public Object hello(Integer id, String name) {
return null;
}
}
子类重写字段、重写方法都没用的;
只会校验父类的字段、方法;
3、springwebmvc Controller
springwebmvc Controller
不可以实现接口, 为了实现参数校验;
所以没人写controller实现接口。
api接口参数校验不起作用, 如果实现了接口。
4、@NotEmpty
仅支持 字符串、数组、集合; 不支持Float等类型
探讨了在Java中使用@Validated注解进行参数校验的限制,特别是在实现接口时的问题。指出在子类重写方法时,参数约束配置不能重新定义,且只有根方法可以标注参数约束。此外,Spring WebMVC Controller实现接口会遇到参数校验失效的情况。


被折叠的 条评论
为什么被折叠?



