当绑定(bind)结果有错误处于 Activity 状态时,我想返回 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;
}
}
关于java - Spring MVC 绑定(bind)结果有错误返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42129223/