Tuesday 15 May 2012

spring - HandlerExceptionResolver for annotated controller -


I have an annotated controller in which several mathidas are mapped on the URL. Like this:

  @Controller Public Class Category Controller {@RequestMapping throws parseException @RequestMapping of public zeroes addcategories (@RequestParam (value = "data") string jsonData) Value = "/ getNext") Public Zero getNext (@RequestParam) String jsonData throws ParseException ...}  

Methods to parse the json request and Take action to do something. The parsing request can be checked ParseException which I can handle in the law or its signature throws I like the second approach because it gives me additional code Do not try / hold. So the question is how to configure and code handler for controller methods?

You should see spring documents.

  @Controller Public Class Category Controller {@ExceptionHandler (ParseException.class) Public ModelAndView Handle ParaseExc (ParseException ex) {// ...} @RequestMapping (value = "/ addcategories") Public Zero AddCategories (@RequestParam (value = "data") string jsonData throws ParseException}  

Or if you want to handle these exceptions, then it is in the form of Spring MVC Bean in its XML configuration Declare all your controllers in.


No comments:

Post a Comment