spring 验证框架出现错误ValidationMessages not found排查

错误如下:

2017-06-14 12:41:03,857 DEBUG [org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl] - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.Pattern, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={flags=[Ljavax.validation.constraints.Pattern$Flag;@5c786553, groups=[Ljava.lang.Class;@313a809b, regexp=.*, message={javax.validation.constraints.Pattern.message}, payload=[Ljava.lang.Class;@22cd212b}, constraintType=GENERIC}.

2017-06-14 12:41:03,970 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - ValidationMessages not found.
2017-06-14 12:41:03,977 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - ContributorValidationMessages not found.

2017-06-14 12:41:03,983 DEBUG [org.hibernate.validator.resourceloading.PlatformResourceBundleLocator] - org.hibernate.validator.ValidationMessages found.


因为在controller参数中用了多个ModelAttribute,并且需要验证,所以一直以为是多个ModelAttribute导致的。

后来,发现,是因为验证字段的类型与验证内容不匹配导致。如下

@NotNull(message = "是否激活不能空")
@ApiModelProperty(required = true, value = "激活")
@Pattern(regexp = "^[0-9]*[1-9][0-9]*$", message = "激活必须是数字")
private int is_active;

is_active是int类型,而@Pattern对int类型无效,所以,一只报错


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值