modelAndView 模型视图解析器
两个部分 model 和 view 字面意思哈哈哈哈~
我给spring在index页面里写一个超链接
<a href="request/testModelAndView">testModelAndView</a>
使它点击这个a标签能传一个“request/testModelAndView”映射给servlet。
然后servlet找到相应的方法,进行处理。
model呢,我把理解成仓库,我啥玩意都能往里装。
比如:
@RequestMapping("/testModelAndView")
public ModelAndView mv() {
ModelAndView modelAndView=new ModelAndView(SUCCESS);
//跳转SUCCESS.jsp页面
// modelAndView.addObject(new Date());
modelAndView.addObject("time",new Date());
System.out.println("modelandView test SUcess");
return modelAndView;
}
这里model就是一个时间类。
跳转到sucess.jsp页面后,我在sucess.jsp页面body里加入了这样的代码:
<div style="background:#CCC;color:red ">
request time:${requestScope.time}
</div>
requestScope.time获取modelandview中model的time数据。
总觉得model这里写的跟map有点像,你们觉得呢?
运行如下: