In Spring2.5, we write the controller as follows:
@Controller
public class HelloWorldController{
@RequestMapping(value="/welcome",method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("hello");
model.addObject("msg", "hello world");
return model;
}
}
In Spring 3.1:
@RequestMapping(value="/welcome",method = RequestMethod.GET)
public String printWelcomeString(ModelMap model) {
model.addAttribute("message", "hello world);
return "hello";
}
FunctionprintwelcomeString () returns a string instead of ModelAndView.
Can anyone explain this more? How will it work? How do hello.jsp get the model to display? Thank:)
source
share