我使用 Spring 框架和 bean 驗(yàn)證規(guī)范(休眠實(shí)現(xiàn))。考慮到下面的代碼片段,我使用以下方法進(jìn)行了以下觀(guān)察@ReportAsSingleViolation:@ReportAsSingleViolation添加時(shí)僅返回默認(rèn)消息。我的期望是獲得觸發(fā)失敗的消息而不是默認(rèn)消息。當(dāng)我刪除@ReportAsSingleViolation注釋時(shí),一切都按預(yù)期工作。正確返回與違反約束對(duì)應(yīng)的所有錯(cuò)誤消息。這種行為是描述 Bean 驗(yàn)證規(guī)范的一部分還是實(shí)現(xiàn)問(wèn)題?@Target({ElementType.FIELD, ElementType.PARAMETER})@Retention(RetentionPolicy.RUNTIME)@Constraint(validatedBy = {})//@ReportAsSingleViolation@NotBlank(message = "The input cannot be blank")@Pattern(regexp = "[0-9A-Z_]+", message = "The input must content only uppercase, numbers and undescore")@Size(max = 30, message = "The input must be maximal 30")@Documentedpublic @interface MyAnnotation{ String message() default "{com.example.MyAnnotation.message}"; Class<?>[] groups() default { }; Class<? extends Payload>[] payload() default { };}
添加回答
舉報(bào)
0/150
提交
取消