我想在绑定结果haserror激活时返回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 ?
}
}
答案 0 :(得分:0)
只需返回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;
}
}