mardi 3 mars 2015

How to use the same form DTO, with different validation annotations? How to avoid double code?

Which is the best practice to write DTO and follow different validated annotations, without double my code? Below attached a simple example, that I want to avoid:



public class AddressForm1 {

@NotEmpty
private String address;
@NotNull
@Max(23)
@Min(30)
private BigDecimal lng;

// .... (getters, setters)
}

public class AddressForm2 {

// removed annotation, empty value permitted
private String address;
@NotNull
@Max(43)
@Min(50)
private BigDecimal lng;


// .... (getters, setters)
}

Aucun commentaire:

Enregistrer un commentaire