How to handle validation errors and exceptions in a RESTful Spring MVC controller?

前端 未结 2 598
悲哀的现实
悲哀的现实 2021-01-12 11:53

For example, how to handle validation errors and possible exceptions in this controller action method:

@RequestMapping(method = POST)
@ResponseBody
public Fo         


        
2条回答
  •  半阙折子戏
    2021-01-12 12:48

    Throw an exception if you have an error, and then use @ExceptionHandler to annotate another method which will then handle the exception and render the appropriate response.

提交回复
热议问题