有什么区别
model.addAttribute("名称",value)
和
mv.addObject("name",value)
在 spring-mvc 中?
模特就是模特
mv 是 ModelAndView
最佳答案
Model#addAttribute(String, Object)
州
Add the supplied attribute under the supplied name.
同时 ModelAndView#addObject(String, Object)
州
Add an attribute to the model.
如果你查看addObject
的源代码
public ModelAndView addObject(String attributeName, Object attributeValue) {
getModelMap().addAttribute(attributeName, attributeValue);
return this;
}
它委托(delegate)给 ModelAndView
持有的 Model
引用,并在其上调用 addAttribute()
。
关于java - model.addAttribute ("name",值)和 mv.addObject ("name",值)之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18575777/