我的控制器中有以下 GET 请求:
@Controller
public class TestController {
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setValidator(new ProfileTokenValidator());
}
@RequestMapping(value = "/more/{fromLocation:.+}/to/{toLocation:.+}", method = RequestMethod.GET)
@ResponseBody
public void copyProfile(@PathVariable @Valid String fromLocation, @PathVariable String toLocation) {
...
}
}
我有一个简单的字符串 fromLocation 验证器
public class ProfileTokenValidator implements Validator{
@Override
public boolean supports(Class validatedClass) {
return String.class.equals(validatedClass);
}
@Override
public void validate(Object obj, Errors errors) {
String location = (String) obj;
if (location == null || location.length() == 0) {
errors.reject("destination.empty", "Destination should not be empty.");
}
}
}
当fromLocation与toLocation相同时,我需要为案例提供验证的问题。请提供建议或其他帮助,有没有办法编写验证器来同时检查两个参数以获取获取请求?谢谢。
块引用