Supplementary annotation knowledge
@ModelAttribute
This annotation precedes the parameter, so you can put the value of the parameter directly into the session, create a key-value pair, and give the key itself, so @modelAttribute (” key “) is the parameter value
(uncommon) This annotation precedes methods that do not request processing, and also registers values in the session as key:value, divided into methods that return a value and methods that do not return a value. The difference is that methods with no return value require an explicit addition of the object to the model.
More than one line model. The addAttribute (" key ", "value")
@modelAttribute (“value”) this annotation if it has a value in it, it’s going to put that value in it. You want parameters, for example @modelattribute (” myApp “)
I returned a user object named user, and the foreground fetched the object and asked ${myapp.user. Properties inside the object}
@RequestMapping("/login")
public String login(@ModelAttribute("user") String user, @ModelAttribute("pwd") String pwd) {
System.out.println(user);
System.out.println(pwd);
return "hello";
Copy the code
The value on the front interface can be expressed as EL
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"% > <! DOCTYPE html> <html> <head> <meta charset="UTF-8"</h1> ${user}<br> ${PWD}< /body> </ HTML >Copy the code