spring - modelMap.put() v/s modelMap.addAttribute()

标签 spring spring-mvc

Spring ,有什么区别

modelMap.put("key",value);

modelMap.addAttribute("Key",value);

最佳答案

addAttributes 意味着检查属性名称中是否不为空 -> 请参阅来源

 /**
     * 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/

相关文章:

java - 如何使用泛型实现 Hibernate DAO

java - 层次树角色的 Spring Security/Java EE 解决方案

java - spring web 服务是用来做什么的

java - Tomcat:ExceptionHasndler 不适用于 MultiPartException 但适用于 IllegalArgumentException

spring - 是否可以在运行时的Spring Boot中创建REST端点?

java - 带有 websockets 补丁的 spring

Spring MVC @pathvariable 注解不会将值从接口(interface)传递到实现

java - Spring Boot 启用全局 CORS 支持问题 : only GET is working, POST、PUT 和 Delete 不起作用

java - 创建类路径资源 [META-INF/spring/app-context.xml] 中定义的名称为 'tilesConfigurer' 的 bean 时出错

java - @运行时的值