with respect to javax.validation
@NotNull(message = "From can't be null")
@Min(value = 1, message = "From must be greater than zero")
private Long from;
@NotNull(message = "To can't be null")
@Min(value = 1, message = "To must be greater than zero")
private Long to;
I want to also validate that FROM should be less than TO and TO should be greater than FROM ? how we can do this using javax validation's annotation ?
You need a custom
cross field validationannotation.One way is to annotate your custom class with
@YourCustomAnnotation.In
YourCustomAnnotationValidatoryou have access to your value, hence you can implement your logic there:Then mark your
YourDtoclass with@RangeCheck:Or simply manually validate the relation of two fields.