把 ModelAndView 对象里面的键值对使用request.attribute()放到request域对象里
public ModelAndView addObject(String attributeName, Object attributeValue){
getModelMap().addAttribute(attribute ,attributeValue);
return this;
}
使用方式
超链接
<a href="modelandview">modelandview</a>
JAVA类
@Controller
public class Hello {
@RequestMapping("/modelandview")
public ModelAndView modAndView() {
String forward = "model";
ModelAndView modelAndView = new ModelAndView(forward);
modelAndView.addObject("time",new Date());
return modelAndView;
}
}
model.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>model</title>
</head>
<body>
time : ${requestScope.time}
</body>
</html>