我想要实现的是有序的错误消息。给出以下 bean 类
public class DummyBean{
@NotNull
public String firstName;
@NotNull
public String lastName;
}
并像这样使用LocalValidatorFactoryBean:
private Validator validator;
@Autowired
public DummyController(Validator validator) {
this.validator = validator;
}
public void validate(DummyBean bean){
Map<String, String> failureMessages = new LinkedHashMap<String, String>();
for (ConstraintViolation<DummyBean> failure : validator.validate(bean)) {
failureMessages.put(failure.getPropertyPath().toString(), failure.getMessage());
}
}
如何确保与属性“firstName”相关的错误消息总是首先与“lastName”相关?
只能订购 Afaik 组序列,但我希望也许有人已经遇到过这个问题