草庐IT

constraintViolations

全部标签

java - 如果我在 jsr 303 中使用两个自定义注释,如果第一个验证失败,如何停止对第二个注释的验证?

我在使用jsr303时遇到下一个问题:我用下一种方式注释了字段:@NotEmpty(message="Pleasespecifyyourpostcode")@PostCode(message="Yourpostcodeisincorrect")privateStringpostCode;但只有当字段通过了@NotEmpty的验证时,我才需要检查@PostCode。我如何检查这两个注释?提前致谢 最佳答案 您可以使用验证组来按组执行验证。详见3.4节。JSR-303中的组和组序.在您的示例中,您会执行以下操作:@NotEmpty(me

java - 覆盖 DropWizard ConstraintViolation 消息

SoIwanttochangethevalidationmessagesusedtovalidateamodelthroughaDropWizardresource.I'musingjavabeanvalidationannotations.ForexamplehereisoneofthefieldsIwanttovalidate:@NotEmpty(message="Passwordmustnotbeempty.")Icantestthisworksasexpectedusingavalidator.HoweverwhenIuseDropWizardtodothevalidation