Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9ce74852
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ce74852
编写于
5月 31, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce alias for 'value' attribute in @SessionAttributes
Issue: SPR-11393
上级
6a5b2672
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
43 addition
and
35 deletion
+43
-35
spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.java
...pringframework/web/bind/annotation/SessionAttributes.java
+28
-14
spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java
...rk/web/bind/annotation/support/HandlerMethodResolver.java
+2
-2
spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
...ework/web/method/annotation/SessionAttributesHandler.java
+3
-3
spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java
.../web/method/annotation/SessionAttributesHandlerTests.java
+8
-14
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
...vlet/mvc/annotation/ServletAnnotationControllerTests.java
+1
-1
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
...tation/ServletAnnotationControllerHandlerMethodTests.java
+1
-1
未找到文件。
spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.java
浏览文件 @
9ce74852
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -23,11 +23,14 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.core.annotation.AliasFor
;
/**
* Annotation that indicates the session attributes that a specific handler
* uses. This will typically list the names of model attributes which should be
* Annotation that indicates the session attributes that a specific handler uses.
*
* <p>This will typically list the names of model attributes which should be
* transparently stored in the session or some conversational storage,
* serving as form-backing beans. <b>Declared at the type level
,</b>
applying
* serving as form-backing beans. <b>Declared at the type level
</b>,
applying
* to the model attributes that the annotated handler class operates on.
*
* <p><b>NOTE:</b> Session attributes as indicated using this annotation
...
...
@@ -44,11 +47,12 @@ import java.lang.annotation.Target;
* generic {@link org.springframework.web.context.request.WebRequest} interface.
*
* <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
* make sure to consistently put <i>all</i> your mapping annotations
- such as
*
{@code @RequestMapping} and {@code @SessionAttributes} -
on
* make sure to consistently put <i>all</i> your mapping annotations
—
*
such as {@code @RequestMapping} and {@code @SessionAttributes} —
on
* the controller <i>interface</i> rather than on the implementation class.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 2.5
*/
@Target
({
ElementType
.
TYPE
})
...
...
@@ -58,18 +62,28 @@ import java.lang.annotation.Target;
public
@interface
SessionAttributes
{
/**
* The names of session attributes in the model, to be stored in the
* session or some conversational storage.
* <p>Note: This indicates the model attribute names. The session attribute
* names may or may not match the model attribute names; applications should
* not rely on the session attribute names but rather operate on the model only.
* Alias for {@link #names}.
*/
@AliasFor
(
attribute
=
"names"
)
String
[]
value
()
default
{};
/**
* The types of session attributes in the model, to be stored in the
* session or some conversational storage. All model attributes of this
* type will be stored in the session, regardless of attribute name.
* The names of session attributes in the model that should be stored in the
* session or some conversational storage.
* <p><strong>Note</strong>: This indicates the <em>model attribute names</em>.
* The <em>session attribute names</em> may or may not match the model attribute
* names. Applications should therefore not rely on the session attribute
* names but rather operate on the model only.
* @since 4.2
*/
@AliasFor
(
attribute
=
"value"
)
String
[]
names
()
default
{};
/**
* The types of session attributes in the model that should be stored in the
* session or some conversational storage.
* <p>All model attributes of these types will be stored in the session,
* regardless of attribute name.
*/
Class
<?>[]
types
()
default
{};
...
...
spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java
浏览文件 @
9ce74852
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -107,7 +107,7 @@ public class HandlerMethodResolver {
SessionAttributes
sessionAttributes
=
AnnotationUtils
.
findAnnotation
(
handlerType
,
SessionAttributes
.
class
);
this
.
sessionAttributesFound
=
(
sessionAttributes
!=
null
);
if
(
this
.
sessionAttributesFound
)
{
this
.
sessionAttributeNames
.
addAll
(
Arrays
.
asList
(
sessionAttributes
.
value
()));
this
.
sessionAttributeNames
.
addAll
(
Arrays
.
asList
(
sessionAttributes
.
names
()));
this
.
sessionAttributeTypes
.
addAll
(
Arrays
.
asList
(
sessionAttributes
.
types
()));
}
}
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
浏览文件 @
9ce74852
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -70,8 +70,8 @@ public class SessionAttributesHandler {
SessionAttributes
annotation
=
AnnotationUtils
.
findAnnotation
(
handlerType
,
SessionAttributes
.
class
);
if
(
annotation
!=
null
)
{
this
.
attributeNames
.
addAll
(
Arrays
.
asList
(
annotation
.
value
()));
this
.
attributeTypes
.
addAll
(
Arrays
.
<
Class
<?>>
asList
(
annotation
.
types
()));
this
.
attributeNames
.
addAll
(
Arrays
.
asList
(
annotation
.
names
()));
this
.
attributeTypes
.
addAll
(
Arrays
.
asList
(
annotation
.
types
()));
}
for
(
String
attributeName
:
this
.
attributeNames
)
{
...
...
spring-web/src/test/java/org/springframework/web/method/annotation/SessionAttributesHandlerTests.java
浏览文件 @
9ce74852
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -16,9 +16,9 @@
package
org.springframework.web.method.annotation
;
import
java.util.HashSet
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.mock.web.test.MockHttpServletRequest
;
...
...
@@ -40,20 +40,13 @@ import static org.junit.Assert.*;
*/
public
class
SessionAttributesHandlerTests
{
private
Class
<?>
handlerType
=
SessionAttributeHandler
.
class
;
private
SessionAttributesHandler
sessionAttributesHandler
;
private
final
SessionAttributeStore
sessionAttributeStore
=
new
DefaultSessionAttributeStore
();
private
SessionAttributeStore
sessionAttributeStore
;
private
final
SessionAttributesHandler
sessionAttributesHandler
=
new
SessionAttributesHandler
(
SessionAttributeHandler
.
class
,
sessionAttributeStore
);
private
NativeWebRequest
request
;
private
final
NativeWebRequest
request
=
new
ServletWebRequest
(
new
MockHttpServletRequest
())
;
@Before
public
void
setUp
()
{
this
.
sessionAttributeStore
=
new
DefaultSessionAttributeStore
();
this
.
sessionAttributesHandler
=
new
SessionAttributesHandler
(
handlerType
,
sessionAttributeStore
);
this
.
request
=
new
ServletWebRequest
(
new
MockHttpServletRequest
());
}
@Test
public
void
isSessionAttribute
()
throws
Exception
{
...
...
@@ -115,7 +108,8 @@ public class SessionAttributesHandlerTests {
assertTrue
(
sessionAttributeStore
.
retrieveAttribute
(
request
,
"attr3"
)
instanceof
TestBean
);
}
@SessionAttributes
(
value
=
{
"attr1"
,
"attr2"
},
types
=
{
TestBean
.
class
})
@SessionAttributes
(
names
=
{
"attr1"
,
"attr2"
},
types
=
{
TestBean
.
class
})
private
static
class
SessionAttributeHandler
{
}
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
浏览文件 @
9ce74852
...
...
@@ -2163,7 +2163,7 @@ public class ServletAnnotationControllerTests {
@Controller
@RequestMapping
(
"/myPage"
)
@SessionAttributes
(
{
"object1"
,
"object2"
})
@SessionAttributes
(
names
=
{
"object1"
,
"object2"
})
public
static
class
MySessionAttributesController
{
@RequestMapping
(
method
=
RequestMethod
.
GET
)
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
浏览文件 @
9ce74852
...
...
@@ -1774,7 +1774,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Controller
@RequestMapping
(
"/myPage"
)
@SessionAttributes
(
{
"object1"
,
"object2"
})
@SessionAttributes
(
names
=
{
"object1"
,
"object2"
})
public
static
class
MySessionAttributesController
{
@RequestMapping
(
method
=
RequestMethod
.
GET
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录