Passe as informações para a página da Springmvc com o objeto Org.springframework.ui.model
Requer: suporte JSTL e expressões EL
1.Maven Adicionar dependências:
<!-JSTL (Biblioteca de tags padrão JSP)->; dependência> <PuerpId> jstl </roupdiD> <TRATIFACTID> jstl </artifactId> <versão> 1.2 </versão;/dependency>
2. Métodos no controlador
/** **/@controlador@requestmapping ("/hello") classe pública hellocontroller {/***Endereço de solicitação: nome do projeto/hello/userinfo*@return*/@requestMapp ("userinfo") public string userinfo (org.springframe.ui.model, map <string, mapa). UserInfomodel ("Zhang san", 99, "masculino"); model.addattribute ("info", info); list <userInfomodel> list = new ArrayList <suserInfomodel> (); list.add (new Userinfomodel ("li si", 20, "masculino"); list.add (novo userinfomodel ("li si", 20, "mascous); 21, "feminino")); list.add (novo userInfomodel ("zhao liu", 22, "masculino")); // Passe vários objetos map.put ("user_list", list); retornar "hello/userinfo"; // O endereço físico do splicing de prefixo (prefixo) + valor de retorno + sufixo) definido em servlet.xml}}3. Objetos da entidade de teste
pacote Demo.models.hello; importar java.util.date;/** **/public class UserInfomodel {public userInfomodel (nome da string, Int Age, String Sex) {this Date (Nome; Nome; this.Age; Age; this.sex = sexo; this.date = new Date ();} string; string; string; string; string; void setDate (data de data) {this.date = date;} public string getName () {retorna nome;} public void SetName (string name) {this.name = name;} public int getage () {string string;} public void setage (int age) {this.age = Age;} string; sexo;}}4.JSP Página
<%@ página de página = "java" contentType = "text/html; charset = utf-8" pageEncoding = "utf-8"%> <!-Apresente a biblioteca do núcleo jstl, use o loop tag-> <%@ taglib uri = "http:/java.sun.com/JSPSJ/JSPJUJO Biblioteca FMT, formate a tag de tempo-> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%> <!-Invoke El Support-> <%@ PageSelined = "false" "%> <! Transitória // pt "" http://www.w3.org/tr/html4/loose.dtd"><html> <head><meta http-equiv = "content-type" content = "text/html; scr = "/Content/index.js"> </sCript> <link href = "/content/index.css" rel = "Nofollow externo"/> </head> <body> <h3> informações </h3> <div> url: $ {pageContext.request.ContextPath} </div> <H3> $ {info.name} </div> <div> idade: $ {info.age} </div> <div> sexo: $ {info.sex} </div> <div> Data: <fmt: formatdate padrony = "yyyyy-mm-dd hh: mm: ss" = "" $ {info.date} " List </h3> <table> <tt> <td> nome </td> <td> idade </td> <td> sexo </td> <td> data </td> </tr> <c: foreach itens = "$ {user_list}" var = "p"> <tr> <td> $ {p.name} </td> <td> $ {p.age} </td> <td> $ {p.sex} </td> <td> <fmt: formatdate padrony = "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> linha Número </td> <td> col1 </td> <td> col2 </td> <td> col3 </td> </tr> <c: foreach iniciar = "1" end = "5" var = "i"> <tr> <td> $ {i} </td> <td> $ {i+2} </td> <td> $ {i+3} </td> <td> $ {i+4} </td> </thO método acima de transmitir valores para a página do Java-JSP Springmvc-Controller é todo o conteúdo que compartilho com você. Espero que você possa lhe dar uma referência e espero que você possa apoiar mais o wulin.com.