Deal with @ResponseBody in Spring mvc
Ways to resolve views in Spring MVC
- Return a
Stringwith the view name and add attributes to theModelorModelMap - Return a
ModelAndViewwith the view name and model - Return an
Objectwith a@ResponseBodyannotation -when we want to return json/xml
@ResponseBody -it is an Spring annotation that dealt with ajax response when we are using ajax call.
@Requestmapping(value="/states", method=RequestMethod.GET) public @ResponseBody List<State> stateList() { return serviceImpl.getAllState(); }
OR
@RequestMapping(value="/states", method=RequestMethod.GET ,
produces={"application/json","application/xml"}) @ResponseBody public List<State> AllState() { returnserviceImpl.getAllState(); }
Comments
Post a Comment