Modelandview returns model data and views. Refer to the demo code below to see how it is implemented. Focus on the construction method of creating Modelandview through the view name, and how the model data is obtained by means of ${requestscope.attribute}.
Controller code:
Packagecom.tiekui.springmvc.handlers;Importjava.util.Date;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.servlet.ModelAndView; @Controller Public classmodelandviewtest {@RequestMapping ("Testmodelandview") PublicModelandview Testmodelandview () {String viewname= "Success"; Modelandview Modelandview=NewModelandview (viewname); Modelandview.addobject ("Time",NewDate ()); returnModelandview; }}
View Code success.jsp:
<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 " pageencoding=" Iso-8859-1 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > </body>
View Code index.jsp
< BR > < href= "Testmodelandview">modelandview</a > <br>
SPRINGMVC (14) requestmapping Modelandview