I\'ve seen examples where a controller returns a String (which indicates the view)
@RequestMapping(value=\"/owners/{ownerId}\", method=RequestMethod.GET)
pub
In Spring MVC, you should return ModelAndView if you want to render jsp page
For example:
@RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView indexView(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
this function will return index.jsp when you are hitting /index.html
In addition you can return any JSON or XML object using @ResponseBody annotation and serializer.
For example:
@RequestMapping(value="/getStudent.do",method=RequestMethod.POST)
@ResponseBody
public List getStudent(@RequestParam("studentId") String id){
List students = daoService.getStudent(id);
return students;
}
In this example you will return List as JSON in case and you have enabled Jackson serializer. In order to enable that you need to add the following to your Spring XML:
And the Serializer itself:
Hope it helps.