Spring-MVC 里面的ModelAndView
作用:
由于本身http是无状态的并不会保存什么请求信息。 但是目标页面可能又需要一些信息。这时候可以用ModelAndView存放一些业务数据之类等。然后返回给页面
用法:
比较重要的方法:
往对象里面加入变量
/**
* Add an attribute to the model.
* @param attributeName name of the object to add to the model (never {@code null})
* @param attributeValue object to add to the model (can be {@code null})
* @see ModelMap#addAttribute(String, Object)
* @see #getModelMap()
*/
public ModelAndView addObject(String attributeName, @Nullable Object attributeValue) {
getModelMap().addAttribute(attributeName, attributeValue);
return this;
}

![Spring-MVC 里面的ModelAndView[编程语言教程]](https://www.zixueka.com/wp-content/uploads/2024/01/1706714511-702f00b26acf8b5.jpg)
