Spring2.5和Spring3.1的区别:ModelAndView
在Spring2.5中,我们编写控制器如下:Spring2.5和Spring3.1的区别:ModelAndView,spring,spring-mvc,Spring,Spring Mvc,在Spring2.5中,我们编写控制器如下: @Controller public class HelloWorldController{ @RequestMapping(value="/welcome",method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exc
@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;
}
}
在春季3.1:
@RequestMapping(value="/welcome",method = RequestMethod.GET)
public String printWelcomeString(ModelMap model) {
model.addAttribute("message", "hello world);
return "hello";
}
函数的作用是:返回一个字符串,而不是ModelAndView
有人能再解释一下吗?
它将如何工作?
如何让hello.jsp获取要显示的模型?
谢谢:)Spring3.5尚未发布,我希望您指的是Spring3.1
returnmodelandview
是一种旧式的代码编写方式,在Spring2.0中使用。在Spring3.0AddLater中,您可以同时返回ModelAndView或nameView
我建议您返回always String(视图名称),因为Spring MVC的一些高级功能无法正常工作:
例如: