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