0
春1.3.5春自定義驗證國際化
我創建與org.springframework.validation.Validator
界面自定義驗證了一把。我試圖使用本地化的錯誤消息。作爲測試的驗證,我有以下幾點:
@Component
public class RegionValidator implements Validator {
@Autowired
RegionService regionService;
@Autowired
private MessageSource messageSource;
@Override
public boolean supports(Class<?> clazz) {
return Region.class.isAssignableFrom(clazz);
}
@Override
public void validate(Object target, Errors errors) {
String message = messageSource.getMessage("region.name.unique", null, null);
errors.rejectValue("name", "region.name.unique", "Name must be unique");
}
}
在我application.yml
我有以下幾點:
在驗證碼,我得到了正確的消息messageSource
卻怎麼也我得到errors.rejectValue
根據給定的代碼查找消息?