2017-02-09 8 views
1

bindingエラーhaserrorがアクティブなときにhttpエラーを返すか、メソッドから終了したいのですがどうすればいいですか?Spring MVC bindingresult haserror 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{ 
      // How i can exit without return any Node object ? 
     } 
    } 

答えて

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; 
     } 
    } 
+0

エラーが発生したとき、それは新しいノードを作成するdoesntの、どうもありがとうございました、それが助け場合) –

+0

は、感謝の答えを受け入れます。 – mhshimul

関連する問題