我在 Spring MVC 项目中获得了表单对象的 Spring Validator,我需要做一些部分基于客户端 IP 地址的验证。是否有可能在验证器中获得类似 request.getRemoteAddr() 的东西?
//controler
public String saveForm(@Valid @ModelAttribute("command") MyCommand myCommand, BindingResult result) {
//some code
return "viewName";
}
//Validator
public class MyValidator implements Validator {
@Override
public void validate(Object target, Errors errors) {
String requestIp = ?
}
}