在 Spring ,有什么区别
modelMap.put("key",value);
和
modelMap.addAttribute("Key",value);
最佳答案
addAttributes表示检查属性名称中的非null->参见源
/**
* Add the supplied attribute under the supplied name.
* @param attributeName the name of the model attribute (never <code>null</code>)
* @param attributeValue the model attribute value (can be <code>null</code>)
*/
public ModelMap addAttribute(String attributeName, Object attributeValue) {
Assert.notNull(attributeName, "Model attribute name must not be null");
put(attributeName, attributeValue);
return this;
}
关于spring - modelMap.put()v/s modelMap.addAttribute(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15742262/