This commit is contained in:
Rossen Stoyanchev
2017-09-08 07:53:23 -04:00
parent 8f78c772b5
commit bc470fca30
6 changed files with 48 additions and 39 deletions

View File

@@ -243,13 +243,12 @@ public final class ModelFactory {
/**
* Derive the model attribute name for a method parameter based on:
* <ol>
* <li>the parameter {@code @ModelAttribute} annotation value
* <li>the parameter type
* </ol>
* Derive the model attribute name for the given method parameter based on
* a {@code @ModelAttribute} parameter annotation (if present) or falling
* back on parameter type based conventions.
* @param parameter a descriptor for the method parameter
* @return the derived name (never {@code null} or empty String)
* @return the derived name
* @see Conventions#getVariableNameForParameter(MethodParameter)
*/
public static String getNameForParameter(MethodParameter parameter) {
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);

View File

@@ -74,10 +74,7 @@ public class SessionAttributesHandler {
this.attributeNames.addAll(Arrays.asList(annotation.names()));
this.attributeTypes.addAll(Arrays.asList(annotation.types()));
}
for (String attributeName : this.attributeNames) {
this.knownAttributeNames.add(attributeName);
}
this.knownAttributeNames.addAll(this.attributeNames);
}
/**
@@ -90,7 +87,7 @@ public class SessionAttributesHandler {
/**
* Whether the attribute name or type match the names and types specified
* via {@code @SessionAttributes} in underlying controller.
* via {@code @SessionAttributes} on the underlying controller.
* <p>Attributes successfully resolved through this method are "remembered"
* and subsequently used in {@link #retrieveAttributes(WebRequest)} and
* {@link #cleanupAttributes(WebRequest)}.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -30,12 +30,15 @@ import org.springframework.web.bind.support.SessionAttributeStore;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Test fixture with {@link SessionAttributesHandler}.
*
* @author Rossen Stoyanchev
*/
public class SessionAttributesHandlerTests {
@@ -50,10 +53,10 @@ public class SessionAttributesHandlerTests {
@Test
public void isSessionAttribute() throws Exception {
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr2", null));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr1", String.class));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("attr2", String.class));
assertTrue(sessionAttributesHandler.isHandlerSessionAttribute("simple", TestBean.class));
assertFalse(sessionAttributesHandler.isHandlerSessionAttribute("simple", null));
assertFalse(sessionAttributesHandler.isHandlerSessionAttribute("simple", String.class));
}
@Test