SpringMVC(十五) RequestMapping map模型数据
控制器中使用map模型数据,传送数据给视图。
控制器参考代码:
package com.tiekui.springmvc.handlers; import java.util.Arrays; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array; import com.tiekui.springmvc.pojo.Address; import com.tiekui.springmvc.pojo.User; @Controller public class MapModel { @RequestMapping("testMapModel") public String testMapModel(Map<String, Object> map) { User userTk = new User(); Address address = new Address(); address.setCity("city"); address.setProvince("province"); userTk.setAge(19); userTk.setEmail("zhoutiekui@huawei.com"); userTk.setPassword("test"); userTk.setUsername("zhoutiekui"); userTk.setAddress(address); map.put("user", userTk); map.put("names", Arrays.asList("zhoutiekui","chaoer")); return "mapView"; } }
返回视图参考代码:
<%@ 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"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> user: ${requestScope.user} names: ${requestScope.names} </body> </html>
调用视图参考代码:
<a href="testMapModel">testMapModel video 15</a>
https://github.com/godmaybelieve