3
在Spring2.5我們寫控制器等如下:差:ModelAndView的
@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;
}
}
在Spring 3.1:
@RequestMapping(value="/welcome",method = RequestMethod.GET)
public String printWelcomeString(ModelMap model) {
model.addAttribute("message", "hello world);
return "hello";
}
printwelcomeString()函數返回一個String而不是ModelAndView。
任何人都可以解釋它嗎? 它將如何工作? hello.jsp如何讓模型顯示? 謝謝:)