我有很多控制器。所有这些都扩展了AbstractController。许多控制器实现了验证方法。 如何在AbstractController中编写通用验证方法?
public class CarSearchCriteria extends AbstractController {
...
public static final String VALIDATE = "/validate";
private static final String TEMPLATE_PATH = "car/car_search";
private static final String EMPTY_RESULT = " :: div-car-search";
private static final String RESULT = " :: div-car-search-result";
private static final String SEARCH_CRITERA = "carSearchCriteria";
@RequestMapping(value = VALIDATE, method = RequestMethod.POST)
public String validate(@Valid @ModelAttribute(SEARCH_CRITERA) CarSearchCriteria criteria, final BindingResult bindingResult,
Model model) {
if (bindingResult.hasErrors()) {
return TEMPLATE_PATH + EMPTY_RESULT;
}
return TEMPLATE_PATH + RESULT;
}
...
}
public abstract class AbstractController {
...
}