Springmvc Getting Started-05

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.