Spring MVC 绑定结果出错 return
Spring MVC bindingresult haserror return
我想 return 当 bindingresult 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 ?
}
}
只是 return 空。
@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;
}
}
我想 return 当 bindingresult 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 ?
}
}
只是 return 空。
@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;
}
}