简体   繁体   中英

Is it possible to inline multiple javax validation annotations and express as one message?

I'm currently getting a bit more familiar with javax validation and custom constraints, and was wondering if it was possible to inline multiple constraints together and report them as a single violation, rather than creating my own custom contraint annotation?

eg something like the below (syntax obviously not valid, but hopefully you get the idea)

constraint {
  @NotNull
  @Size(min = 2, max = 14)
  @CheckCase(CaseMode.UPPER)
}
@ReportAsSingleViolation
private String license

@NotNull
private String name

通过定义Groups可以做到这一点。

Probably if one constraint fails you do not want to check another so use @GroupSequence .

It will ensure that it will fail on first error found. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM