[3] Spring MVC Learning Notes

Source: Internet
Author: User

Spring MVC Pass Value

First of all, the value is divided into 2 parts,

The view layer passes values to the control layer and passes the value of the control layer to the view layer

1. The view layer passes the value to the control layer, passing through the string username parameter;
2. The value of the control layer to the view layer, through the model parameter to pass, the foreground through ${username} to accept, wherein model can be regarded as a map, is a form of key-value pairs.

Control Layer Code:

  @Controller public  class Myfirstcontroller {//requestmapping indicates which URL to use for the//view layer to pass the value to the control layer, via the string username parameter incoming// The value of the control layer to the view layer, through the model parameter to pass, the foreground through ${username} to accept, where model can be regarded as a map, is a form of key-value pairs. @RequestMapping ("/hello") Public String HelloWorld (string Username,model Model) {System.out.println (username); Model.addattribute ("username", username);//The key is not specified here, which is equivalent to the default, that is, Model.addattribute ("string", username); Model.addattribute (username);//This is the name of the logical view return "Hello";}

Configuration file not much to say, not clear can refer to the previous tutorial

Then the view layer

<body>        Note-based spring MVC <br/>        user name  ${username} <br/>   method ${string} </without key  Body>

At the end of this URL, the following page is displayed, as described in the entire pass-through process.



[3] Spring MVC Learning Notes

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.