303va对两个或更多字段使用类级自定义约束验证时,如何在ui(jsp页)中显示错误

a6b3iqyw  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(189)

这是我的modelobject和classlevelconstraint注解

@AtLeastOneNotEmptyConstraint(fields= {"dob","age"})
public class PersonVO  implements Serializable {

    @NotBlank(message = "Eyes cannot not be null")
    private String eyes;
    @NotBlank(message = "Hair cannot not be null")
    private String hair;
    private String dob;
    private String age;

}

    @Constraint(validatedBy =AtLeastOneNotEmptyValidator.class)
@Target({ElementType.TYPE,ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface AtLeastOneNotEmptyConstraint {

    String message() default "Either dob or Age is manidtory";

      String[] fields();

      Class<?>[] groups() default {};

      Class<? extends Payload>[] payload() default {};

}

有人能帮助我如何在jsp页面中显示字段级的错误消息吗<form:errors path=“age”cssclass=“error”/>。但由于它适用于两个feild,我不知道如何应用于每个字段,因为feild在绑定结果中显示为数组。

enter code here

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题