`No validator could be found for constraint ‘javax.validation.constraints.NotEmpty’ 问题的解决
错误的全部提示
.m.m.a.ExceptionHandlerExceptionResolver : Resolved [javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.lang.Integer'. Check configuration for 'stock']
解决问题
我的错误代码:
private Integer id;
//name
@NotEmpty(message = "商品名称不能为空")
private String title;
@NotEmpty(message = "商品价格不能为空")
@Min(value = 0,message = "商品价格必须大于0")
private BigDecimal price;
//stock
@NotEmpty(message = "库存不能不能不填")
private Integer stock;
//des
@NotEmpty(message = "商品描述不能为空")
private String description;
//销量
private Integer sales;
//图片url
@NotEmpty(message = "图片信息不能为空")
private String imgUrl;
然而:
* @NotNull
* 不能为null,但可以为empty (""," "," ")
* 2.@NotEmpty
* 不能为null,而且长度必须大于0 (" "," ") 只能使用在字符串上
* 3.@NotBlank
* 只能作用在String上,不能为null,而且调用trim()后,长度必须大于0 ("test") 即:必须有实际字符
将其中的NotEmpty修改为NotNull后
private Integer id;
//name
@NotEmpty(message = "商品名称不能为空")
private String title;
@NotNull(message = "商品价格不能为空")
@Min(value = 0,message = "商品价格必须大于0")
private BigDecimal price;
//stock
@NotNull(message = "库存不能不能不填")
private Integer stock;
//des
@NotEmpty(message = "商品描述不能为空")
private String description;
//销量
private Integer sales;
//图片url
@NotEmpty(message = "图片信息不能为空")
private String imgUrl;
正常运行!