SpringMVC in modelAttribute comment

1. Notes modifying parameters, pay attention to the point, although not where the user object is added to the model, but springmvc will be automatically added to it, key for the class name in lowercase, value for the current object

@RequestMapping("/testModelAttr")
    public String testModelAttr(User user,Model model){
        System.out.println(model);
        return "/result";
    }

Here Insert Picture Description
You can specify key value added @ModelAttribute
Here Insert Picture Description
Here Insert Picture Description

When 2. @ modelAttribute modification method, when it is placed on the method no matter what request will first call the method

Note: This method also has model, model if in this method of accessing a key1, when you call on the request method into the model in key2, when the key1 == key2 not real time, key2 will cover key1, pay attention here but to cover the key value corresponding to replace

@ModelAttribute
    public void test2(){
        System.out.println("来到了ModelAttribute");
    }
Published 47 original articles · won praise 6 · views 2193

Guess you like

Origin blog.csdn.net/weixin_44467251/article/details/102732828