いずれかのフィールドが有効であるか、別のフィールドが有効であるという方法で、要求クラスの 2 つのフィールドを検証したいと考えています。
例: リクエスト Bean
public class CarRequest {
@NotEmpty
private String customerName;
@NotEmpty
private String customerId;
コントローラーの方法
public @ResponseBody CarResponse addCar(
@ModelAttribute @Valid CarRequest request, BindingResult results)
throws RuntimeException, ValidationException {
if (results.hasErrors()) {
LOG.error("error occured while adding the car");
throw new ValidationException(
"Error Occoured while validiating car request");
}
}
ここで、customerName が NotEmpty であるか、customerId が NotEmpty であるかを確認します。その後、私の検証に合格する必要があります。どうすれば実装できますか。提案してください!!