Übergeben Sie Informationen an die Seite von SpringMVC mit dem org.springframework.ui.model -Objekt oder Kartenobjekt
Erfordert: JSTL -Unterstützung und EL -Ausdrücke
1.Maven Abhängigkeiten hinzufügen:
<!-JSTL (JSP-Standard-Tag-Bibliothek)->; Abhängigkeit> <gruppe> JSTL </GroupId> <artifactId> JSTL </artifactId> <version> 1.2 </Version>;/Deponcy>
2. Methoden im Controller
/** **/@controller@requestmapPing ("/hello") public class hellocontroller {/***Anforderungsadresse: Projektname/Hallo/userInfo*@return*/@requestMapping ("userInfo") public string userInfo (org.springFramework.Ui.Model -model, map <string {String). UserInFomodel ("Zhang san", 99, "männlich"); model.addAttribute ("info", info); list <UserInfomodel> list = new ArrayList <userInfomodel> (); list.add (new userInFomodel ("li si", 20 "," male "); list.add.add (new userInfomodel (" wu. ")). 21, "weiblich")); list.add (neuer userInfomodel ("zhao liu", 22, "männlich"); // Mehrere Objekte map.put ("user_list", list); zurück "hello/userInfo"; // Die physikalische Adresse des Spleißens von Präfix (Präfix) + Rückgabewert + Suffix) definiert in servlet.xml}}3.. Testentität Objekte
Paket Demo.Models.hello; import Java.util.date;/** **/public class UserInfomodel {public userInFomodel (String -Name, int Alter, String Sex) {this.name = name; this.age = Alter; 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 Seite
<%@ page Language = "java" contentType = "text/html; charset = utf-8" pageCoding = "utf-8"%> <!-Führen Sie die JSTL-Kernbibliothek ein. FMT-Bibliothek, formatieren Sie das Zeit-Tag-> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%> <! Transitional // en "" http://www.w3.org/tr/html4/loose.dtd"><Html><Head><Meta http-equiv = "content-type" content = "text/html; href = "/content/index.css" rel = "externer nofollow"/> </head> <body> <h3> Seiteninformationen </h3> <div> url: $ {pageContext.Request.ContextPath} </div> <H3> Benutzerinformationen </h3> <div> name: $ {Info.name} </div> </div> ay: {{{{{{{{{{{oder $ {info.age} </div> <div> sex: $ {info.sex} </div> <div> Datum: <fmt: formatdate muster = "yyyy-mm-dd hh: mm: ss" value = "$ {info.date}"/> </div> <h3> user user user. Liste </h3> <table> <tt> <td> Name </td> <td> Alter </td> <td> Sex </td> <td> Datum </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 muster = "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> Zeile Nummer </td> <td> col1 </td> <td> col2 </td> <td> col3 </td> </tr> <c: foreach start = "1" end = "5" var = "i"> <tr> <td> $ {i} </td> <td> $ {i+2} </td> <td> $ {i+3} </td> <td> $ {i+4} </td> </tr> </c: foreeAl> </table> </body> </html>Die obige Methode zum Übergeben von Werten an die Seite von Java-JSP SpringMVC-Controller ist der gesamte Inhalt, den ich mit Ihnen teile. Ich hoffe, Sie können Ihnen eine Referenz geben und ich hoffe, Sie können wulin.com mehr unterstützen.