'How to implement org.springframework.validation.Validator correctly?
I have seen the following validations are done in Spring Boot. I just wanted to validate some validation logic before saving the data to Database. So can anybody give me an example of how to do this properly? I just wanted to throw exceptions if the logic is failed. Is this achievable using this org.springframework.validation.Validator
?
import org.springframework.validation.Validator;
public class CustomValidator implements Validator {
@Autowired
private SpringValidatorAdapter validator;
public boolean supports(Class<?> clazz) {
return Custom.class.equals(clazz);
}
public void validate(Object o, Errors e) {
validator.validate(o, e);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|