Pass information to springmvc's page with the org.springframework.ui.Model object or Map object
Requires: jstl support and EL expressions
1.maven add dependencies:
<!-- jstl(jsp standard tag library) --> ;dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> ;/dependency>
2. Methods in controller
/** **/@Controller@RequestMapping("/hello")public class HelloController {/** * Request address: project name/hello/userinfo * @return */@RequestMapping("userinfo")public String userinfo(org.springframework.ui.Model model,Map<String, Object> map){//Pass a single object UserInfoModel info = new UserInfoModel("Zhang San",99,"Male");model.addAttribute("info",info);List<UserInfoModel> list = new ArrayList<UserInfoModel>();list.add(new UserInfoModel("Li Si", 20,"Male"));list.add(new UserInfoModel("Wang Wu", 21,"Female"));list.add(new UserInfoModel("Zhao Liu", 22,"Male"));//Pass multiple objects map.put("user_list", list);return "hello/userinfo"; //The physical address of the splicing of prefix (prefix) + return value + suffix) defined in servlet.xml}}3. Test entity objects
package demo.models.hello;import java.util.Date;/** **/public class UserInfoModel {public UserInfoModel(String name,int age,String sex){this.name=name;this.age=age;this.sex=sex;this.date = new Date();}String name;int age;String sex;Date date;public Date getDate() {return date;}public void setDate(Date date) {this.date = date;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}}4.jsp page
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%><!-- Introduce the jstl core library, use the loop tag --><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><!-- Introduce the jstl fmt library, format the time tag --><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %><!-- Invoke EL expression support --><%@ page isELIgnored="false"%><!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=utf-8"><title>Insert title here</title><script scr="/content/index.js"></script><link href="/content/index.css" rel="external nofollow" /></head><body><h3>Page Information</h3><div>url: ${pageContext.request.contextPath}</div><h3>User Information</h3><div>name: ${info.name}</div><div>age: ${info.age}</div><div>sex: ${info.sex}</div><div>date:<fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${info.date}" /></div><h3>User List</h3><table><tt><td>name</td><td>age</td><td>sex</td><td>date</td></tr><c:forEach items="${user_list}" var="p"><tr><td>${p.name}</td><td>${p.age}</td><td>${p.sex}</td><td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${p.date}"/></td></tr></c:forEach><tr><td colspan="4" style="text-align: center;">jstl forEach</td></tr><td>Line number</td><td>col1</td><td>col2</td><td>col3</td></tr><c:forEach begin="1" end="5" var="i"><tr><td>${i}</td><td>${i+2}</td><td>${i+3}</td><td>${i+4}</td></tr></c:forEach></table></body></html>The above method of passing values to the page of java-jsp springmvc-controller is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.