Deal with @ResponseBody in Spring mvc
Ways to resolve views in Spring MVC
- Return a
String
with the view name and add attributes to theModel
orModelMap
- Return a
ModelAndView
with the view name and model - Return an
Object
with a@ResponseBody
annotation -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() { return
serviceImpl.getAllState()
; }
Comments
Post a Comment