0
我在我的控制器以下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相同。 請幫助建議或有什麼,有沒有什麼辦法來編寫驗證器,它將同時檢查兩個參數的Get請求? 謝謝。
塊引用