我想在绑定结果有错误活动时返回http错误或退出方法。我该怎么做?
@RequestMapping(value = "/create", method = RequestMethod.POST)
public Node create(@Valid @RequestBody Node node, BindingResult bindingResult) {
LOG.info(String.format("Create new Node: %s", node));
if (!bindingResult.hasErrors()) {
return nodeService.create(node);
}
else{
// How i can exit without return any Node object ?
}
}
只需返回 null。
@RequestMapping(value = "/create", method = RequestMethod.POST)
public Node create(@Valid @RequestBody Node node, BindingResult bindingResult) {
LOG.info(String.format("Create new Node: %s", node));
if (!bindingResult.hasErrors()) {
return nodeService.create(node);
} else {
return null;
}
}