java model.addAttribute
时间: 2024-05-10 18:21:28 浏览: 113
AddFeature
3星 · 编辑精心推荐
The `model.addAttribute` method is a method provided by the Spring MVC framework in Java, which allows you to add attributes to the model object that will be used to render a view. The `model` object is an instance of the `Model` interface that is passed as a parameter to the controller method.
Here is an example of how to use `model.addAttribute` to add an attribute to the model object:
```
@GetMapping("/hello")
public String hello(Model model) {
String message = "Hello, World!";
model.addAttribute("message", message);
return "hello";
}
```
In this example, we are adding an attribute called "message" with the value "Hello, World!" to the model object. This attribute can then be accessed in the view using the `${message}` expression.
阅读全文