把 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>