Next, I'll show you how to query a single data, which describes the implementation of the show () method. Displaying a single piece of data requires using one of the fields in the users object to query the object, putting the queried data in the model, and returning the user object in the model to the foreground. The code corresponding to the controller class is as follows:
@RequestMapping (value= "/{username}", method=requestmethod.get) public String Show (@ Pathvariable String Username,model Model) { Model.addattribute ("Users", Users.get (username)); return "User/show";}
View Code
After getting the user object, add a query condition on the foreground page, which is accessed using the link: <a href= "${um.value.username}" >${um.value.username}</a> The code that corresponds to the list.jsp page is as follows:
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><%@ taglib Prefix="C"URI="Http://java.sun.com/jsp/jstl/core"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User List</title></Head><Body><ahref= "Add">Add to</a> <C:foreachItems= "${users}"var= "Um" > <ahref= "${um.value.username}">${um.value.username}</a>----${um.value.nickname}----${um.value.password}----${um.value.email}<BR/> </C:foreach></Body></HTML>
View Code
Through the link to jump, the corresponding query out of the page after the user object, display data show.jsp, the corresponding code is as follows:
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><%@ taglib Prefix="SF"URI="Http://www.springframework.org/tags/form" %><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body>Username:${users.username}<BR/>Password:${users.password}<BR/>Nickname:${users.nickname}<BR/>Email:${users.email}<BR/></Body></HTML>
View Code
Springmvc Getting Started-05