SpringBoot实践:使用@Validated相关异常

在使用Spring Boot集成@Validated验证的时候,报出如下错误

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'org.hibernate.validator.constraints.NotBlank' validating type 'java.lang.Integer'. Check configuration for 'displayType'

主要原因是你使用错了注解,@NotBlank注解只能作用于String类型的字段上,如果你把这个注解用在了非String类型的字段上面,就会抛出上面的错误。

具体的做法就是使用@NotNull替换,就可以了。比如:

@NotNull(message = "Banner显示类型不能为空")
private Integer displayType;

猜你喜欢

转载自my.oschina.net/xiaojianyu/blog/1797806