Browse Source

Model interface exposes getAttribute method (next to add/contains)

Fixes gh-22145
pull/22324/head
Juergen Hoeller 7 years ago
parent
commit
5aed117b68
  1. 8
      spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java
  2. 11
      spring-context/src/main/java/org/springframework/ui/Model.java
  3. 13
      spring-context/src/main/java/org/springframework/ui/ModelMap.java

8
spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -161,6 +161,12 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement @@ -161,6 +161,12 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
return containsKey(attributeName);
}
@Override
@Nullable
public Object getAttribute(String attributeName) {
return get(attributeName);
}
@Override
public Map<String, Object> asMap() {
return this;

11
spring-context/src/main/java/org/springframework/ui/Model.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -76,6 +76,15 @@ public interface Model { @@ -76,6 +76,15 @@ public interface Model {
*/
boolean containsAttribute(String attributeName);
/**
* Return the attribute value for the given name, if any.
* @param attributeName the name of the model attribute (never {@code null})
* @return the corresponding attribute value, or {@code null} if none
* @since 5.2
*/
@Nullable
Object getAttribute(String attributeName);
/**
* Return the current set of model attributes as a Map.
*/

13
spring-context/src/main/java/org/springframework/ui/ModelMap.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -144,4 +144,15 @@ public class ModelMap extends LinkedHashMap<String, Object> { @@ -144,4 +144,15 @@ public class ModelMap extends LinkedHashMap<String, Object> {
return containsKey(attributeName);
}
/**
* Return the attribute value for the given name, if any.
* @param attributeName the name of the model attribute (never {@code null})
* @return the corresponding attribute value, or {@code null} if none
* @since 5.2
*/
@Nullable
public Object getAttribute(String attributeName) {
return get(attributeName);
}
}

Loading…
Cancel
Save