Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wqh754186373
spring-framework
提交
76369137
S
spring-framework
项目概览
wqh754186373
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
76369137
编写于
1月 10, 2012
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.1.x'
上级
18b67eed
66df039b
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
163 addition
and
57 deletion
+163
-57
build-spring-framework/resources/changelog.txt
build-spring-framework/resources/changelog.txt
+3
-1
org.springframework.context/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java
...rg/springframework/cache/ehcache/EhCacheCacheManager.java
+10
-3
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java
...ork/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java
+27
-10
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/config/spring-jdbc-3.0.xsd
...urces/org/springframework/jdbc/config/spring-jdbc-3.0.xsd
+2
-3
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/config/spring-jdbc-3.1.xsd
...urces/org/springframework/jdbc/config/spring-jdbc-3.1.xsd
+2
-2
org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java
...g/springframework/orm/hibernate3/SessionFactoryUtils.java
+14
-7
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/SessionFactoryUtils.java
...g/springframework/orm/hibernate4/SessionFactoryUtils.java
+14
-7
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java
...k/web/servlet/mvc/condition/ConsumesRequestCondition.java
+2
-2
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java
...rk/web/servlet/mvc/condition/HeadersRequestCondition.java
+2
-2
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java
...ork/web/servlet/mvc/condition/ParamsRequestCondition.java
+2
-2
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java
...servlet/mvc/condition/RequestMethodsRequestCondition.java
+2
-2
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java
...thod/annotation/ModelAndViewMethodReturnValueHandler.java
+21
-7
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java
...annotation/ModelAndViewMethodReturnValueHandlerTests.java
+58
-9
spring-framework-reference/src/view.xml
spring-framework-reference/src/view.xml
+4
-0
未找到文件。
build-spring-framework/resources/changelog.txt
浏览文件 @
76369137
...
...
@@ -3,10 +3,11 @@ SPRING FRAMEWORK CHANGELOG
http://www.springsource.org
Changes in version 3.1.1 (2012-0
1-1
6)
Changes in version 3.1.1 (2012-0
2-0
6)
-------------------------------------
* official support for Hibernate 4.0 GA
* JBossNativeJdbcExtractor is compatible with JBoss AS 7 as well
* context:property-placeholder's "file-encoding" attribute value is being applied correctly
* DataBinder correctly handles ParseException from Formatter for String->String case
* CacheNamespaceHandler actually parses cache:annotation-driven's "key-generator" attribute
...
...
@@ -14,6 +15,7 @@ Changes in version 3.1.1 (2012-01-16)
* fixed LocalContainerEntityManagerFactoryBean's "packagesToScan" to avoid additional provider scan
* added protected "isPersistenceUnitOverrideAllowed()" method to DefaultPersistenceUnitManager
* Hibernate synchronization properly unbinds Session even in case of afterCompletion exception
* Hibernate exception translation covers NonUniqueObjectException to DuplicateKeyException case
* Hibernate 4 LocalSessionFactoryBean implements PersistenceExceptionTranslator interface as well
* Hibernate 4 LocalSessionFactoryBean does not insist on a "dataSource" reference being set
* added "entityInterceptor" property to Hibernate 4 LocalSessionFactoryBean
...
...
org.springframework.context/src/main/java/org/springframework/cache/ehcache/EhCacheCacheManager.java
浏览文件 @
76369137
...
...
@@ -39,7 +39,15 @@ public class EhCacheCacheManager extends AbstractCacheManager {
/**
* Set the backing EhCache {@link net.sf.ehcache.CacheManager}.
* Returns the backing Ehcache {@link net.sf.ehcache.CacheManager}.
* @return
*/
public
net
.
sf
.
ehcache
.
CacheManager
getCacheManager
()
{
return
cacheManager
;
}
/**
* Sets the backing EhCache {@link net.sf.ehcache.CacheManager}.
*/
public
void
setCacheManager
(
net
.
sf
.
ehcache
.
CacheManager
cacheManager
)
{
this
.
cacheManager
=
cacheManager
;
...
...
@@ -75,5 +83,4 @@ public class EhCacheCacheManager extends AbstractCacheManager {
}
return
cache
;
}
}
}
\ No newline at end of file
org.springframework.jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java
浏览文件 @
76369137
/*
* Copyright 2002-20
08
the original author or authors.
* Copyright 2002-20
12
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.
...
...
@@ -28,7 +28,8 @@ import org.springframework.util.ReflectionUtils;
/**
* Implementation of the {@link NativeJdbcExtractor} interface for JBoss,
* supporting JBoss Application Server 3.2.4+.
* supporting JBoss Application Server 3.2.4+. As of Spring 3.1.1, it also
* supports JBoss 7.
*
* <p>Returns the underlying native Connection, Statement, etc to
* application code instead of JBoss' wrapper implementations.
...
...
@@ -47,11 +48,11 @@ import org.springframework.util.ReflectionUtils;
*/
public
class
JBossNativeJdbcExtractor
extends
NativeJdbcExtractorAdapter
{
private
static
final
String
WRAPPED_CONNECTION_NAME
=
"org.jboss.resource.adapter.jdbc.WrappedConnection"
;
// JBoss 7
private
static
final
String
JBOSS_JCA_PREFIX
=
"org.jboss.jca.adapters.jdbc."
;
private
static
final
String
WRAPPED_STATEMENT_NAME
=
"org.jboss.resource.adapter.jdbc.WrappedStatement"
;
private
static
final
String
WRAPPED_RESULT_SET_NAME
=
"org.jboss.resource.adapter.jdbc.WrappedResultSet"
;
// JBoss <= 6
private
static
final
String
JBOSS_RESOURCE_PREFIX
=
"org.jboss.resource.adapter.jdbc."
;
private
Class
wrappedConnectionClass
;
...
...
@@ -72,10 +73,26 @@ public class JBossNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
* so we can get the underlying vendor connection using reflection.
*/
public
JBossNativeJdbcExtractor
()
{
String
prefix
=
JBOSS_JCA_PREFIX
;
try
{
// trying JBoss 7 jca package first...
this
.
wrappedConnectionClass
=
getClass
().
getClassLoader
().
loadClass
(
prefix
+
"WrappedConnection"
);
}
catch
(
ClassNotFoundException
ex
)
{
// JBoss 7 jca package not found -> try traditional resource package.
prefix
=
JBOSS_RESOURCE_PREFIX
;
try
{
this
.
wrappedConnectionClass
=
getClass
().
getClassLoader
().
loadClass
(
prefix
+
"WrappedConnection"
);
}
catch
(
ClassNotFoundException
ex2
)
{
throw
new
IllegalStateException
(
"Could not initialize JBossNativeJdbcExtractor: neither JBoss 7's ["
+
JBOSS_JCA_PREFIX
+
".WrappedConnection] nor traditional JBoss ["
+
JBOSS_RESOURCE_PREFIX
+
".WrappedConnection] found"
);
}
}
try
{
this
.
wrappedConnectionClass
=
getClass
().
getClassLoader
().
loadClass
(
WRAPPED_CONNECTION_NAME
);
this
.
wrappedStatementClass
=
getClass
().
getClassLoader
().
loadClass
(
WRAPPED_STATEMENT_NAME
);
this
.
wrappedResultSetClass
=
getClass
().
getClassLoader
().
loadClass
(
WRAPPED_RESULT_SET_NAME
);
this
.
wrappedStatementClass
=
getClass
().
getClassLoader
().
loadClass
(
prefix
+
"WrappedStatement"
);
this
.
wrappedResultSetClass
=
getClass
().
getClassLoader
().
loadClass
(
prefix
+
"WrappedResultSet"
);
this
.
getUnderlyingConnectionMethod
=
this
.
wrappedConnectionClass
.
getMethod
(
"getUnderlyingConnection"
,
(
Class
[])
null
);
this
.
getUnderlyingStatementMethod
=
...
...
@@ -85,7 +102,7 @@ public class JBossNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
}
catch
(
Exception
ex
)
{
throw
new
IllegalStateException
(
"Could not initialize JBossNativeJdbcExtractor because
JBoss API classes are not available
: "
+
ex
);
"Could not initialize JBossNativeJdbcExtractor because
of missing JBoss API methods/classes
: "
+
ex
);
}
}
...
...
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/config/spring-jdbc-3.0.xsd
浏览文件 @
76369137
...
...
@@ -12,8 +12,7 @@
<xsd:element
name=
"embedded-database"
>
<xsd:annotation>
<xsd:documentation
source=
"java:org.springframework.jdbc.embedded.EmbeddedDataSourceFactoryBean"
>
<![CDATA[
<xsd:documentation
source=
"java:org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean"
>
<![CDATA[
Creates an embedded database instance and makes it available to other beans as a javax.sql.DataSource.
]]>
</xsd:documentation>
<xsd:appinfo>
...
...
@@ -48,7 +47,7 @@
<xsd:element
name=
"initialize-database"
>
<xsd:annotation>
<xsd:documentation
source=
"java:org.springframework.jdbc.
embedded
.DataSourceInitializer"
>
<![CDATA[
<xsd:documentation
source=
"java:org.springframework.jdbc.
datasource.init
.DataSourceInitializer"
>
<![CDATA[
Initializes a database instance with SQL scripts provided in nested <script/>
elements.
]]>
</xsd:documentation>
</xsd:annotation>
...
...
org.springframework.jdbc/src/main/resources/org/springframework/jdbc/config/spring-jdbc-3.1.xsd
浏览文件 @
76369137
...
...
@@ -12,7 +12,7 @@
<xsd:element
name=
"embedded-database"
>
<xsd:annotation>
<xsd:documentation
source=
"java:org.springframework.jdbc.
embedded.EmbeddedDataSourc
eFactoryBean"
>
<![CDATA[
<xsd:documentation
source=
"java:org.springframework.jdbc.
datasource.embedded.EmbeddedDatabas
eFactoryBean"
>
<![CDATA[
Creates an embedded database instance and makes it available to other beans as a javax.sql.DataSource.
]]>
</xsd:documentation>
<xsd:appinfo>
...
...
@@ -47,7 +47,7 @@
<xsd:element
name=
"initialize-database"
>
<xsd:annotation>
<xsd:documentation
source=
"java:org.springframework.jdbc.
embedded
.DataSourceInitializer"
>
<![CDATA[
<xsd:documentation
source=
"java:org.springframework.jdbc.
datasource.init
.DataSourceInitializer"
>
<![CDATA[
Initializes a database instance with SQL scripts provided in nested <script/>
elements.
]]>
</xsd:documentation>
</xsd:annotation>
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java
浏览文件 @
76369137
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
2
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.
...
...
@@ -32,6 +32,7 @@ import org.hibernate.FlushMode;
import
org.hibernate.HibernateException
;
import
org.hibernate.Interceptor
;
import
org.hibernate.JDBCException
;
import
org.hibernate.NonUniqueObjectException
;
import
org.hibernate.NonUniqueResultException
;
import
org.hibernate.ObjectDeletedException
;
import
org.hibernate.PersistentObjectException
;
...
...
@@ -58,6 +59,7 @@ import org.springframework.dao.CannotAcquireLockException;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.DataAccessResourceFailureException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.dao.IncorrectResultSizeDataAccessException
;
import
org.springframework.dao.InvalidDataAccessApiUsageException
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
...
...
@@ -648,6 +650,17 @@ public abstract class SessionFactoryUtils {
if
(
ex
instanceof
JDBCException
)
{
return
new
HibernateJdbcException
((
JDBCException
)
ex
);
}
// end of JDBCException (subclass) handling
if
(
ex
instanceof
QueryException
)
{
return
new
HibernateQueryException
((
QueryException
)
ex
);
}
if
(
ex
instanceof
NonUniqueResultException
)
{
return
new
IncorrectResultSizeDataAccessException
(
ex
.
getMessage
(),
1
,
ex
);
}
if
(
ex
instanceof
NonUniqueObjectException
)
{
return
new
DuplicateKeyException
(
ex
.
getMessage
(),
ex
);
}
if
(
ex
instanceof
PropertyValueException
)
{
return
new
DataIntegrityViolationException
(
ex
.
getMessage
(),
ex
);
}
...
...
@@ -660,18 +673,12 @@ public abstract class SessionFactoryUtils {
if
(
ex
instanceof
ObjectDeletedException
)
{
return
new
InvalidDataAccessApiUsageException
(
ex
.
getMessage
(),
ex
);
}
if
(
ex
instanceof
QueryException
)
{
return
new
HibernateQueryException
((
QueryException
)
ex
);
}
if
(
ex
instanceof
UnresolvableObjectException
)
{
return
new
HibernateObjectRetrievalFailureException
((
UnresolvableObjectException
)
ex
);
}
if
(
ex
instanceof
WrongClassException
)
{
return
new
HibernateObjectRetrievalFailureException
((
WrongClassException
)
ex
);
}
if
(
ex
instanceof
NonUniqueResultException
)
{
return
new
IncorrectResultSizeDataAccessException
(
ex
.
getMessage
(),
1
,
ex
);
}
if
(
ex
instanceof
StaleObjectStateException
)
{
return
new
HibernateOptimisticLockingFailureException
((
StaleObjectStateException
)
ex
);
}
...
...
org.springframework.orm/src/main/java/org/springframework/orm/hibernate4/SessionFactoryUtils.java
浏览文件 @
76369137
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
2
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,6 +23,7 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.hibernate.HibernateException
;
import
org.hibernate.JDBCException
;
import
org.hibernate.NonUniqueObjectException
;
import
org.hibernate.NonUniqueResultException
;
import
org.hibernate.ObjectDeletedException
;
import
org.hibernate.PersistentObjectException
;
...
...
@@ -47,6 +48,7 @@ import org.springframework.dao.CannotAcquireLockException;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.DataAccessResourceFailureException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.dao.IncorrectResultSizeDataAccessException
;
import
org.springframework.dao.InvalidDataAccessApiUsageException
;
import
org.springframework.dao.InvalidDataAccessResourceUsageException
;
...
...
@@ -164,6 +166,17 @@ public abstract class SessionFactoryUtils {
if
(
ex
instanceof
JDBCException
)
{
return
new
HibernateJdbcException
((
JDBCException
)
ex
);
}
// end of JDBCException (subclass) handling
if
(
ex
instanceof
QueryException
)
{
return
new
HibernateQueryException
((
QueryException
)
ex
);
}
if
(
ex
instanceof
NonUniqueResultException
)
{
return
new
IncorrectResultSizeDataAccessException
(
ex
.
getMessage
(),
1
,
ex
);
}
if
(
ex
instanceof
NonUniqueObjectException
)
{
return
new
DuplicateKeyException
(
ex
.
getMessage
(),
ex
);
}
if
(
ex
instanceof
PropertyValueException
)
{
return
new
DataIntegrityViolationException
(
ex
.
getMessage
(),
ex
);
}
...
...
@@ -176,18 +189,12 @@ public abstract class SessionFactoryUtils {
if
(
ex
instanceof
ObjectDeletedException
)
{
return
new
InvalidDataAccessApiUsageException
(
ex
.
getMessage
(),
ex
);
}
if
(
ex
instanceof
QueryException
)
{
return
new
HibernateQueryException
((
QueryException
)
ex
);
}
if
(
ex
instanceof
UnresolvableObjectException
)
{
return
new
HibernateObjectRetrievalFailureException
((
UnresolvableObjectException
)
ex
);
}
if
(
ex
instanceof
WrongClassException
)
{
return
new
HibernateObjectRetrievalFailureException
((
WrongClassException
)
ex
);
}
if
(
ex
instanceof
NonUniqueResultException
)
{
return
new
IncorrectResultSizeDataAccessException
(
ex
.
getMessage
(),
1
,
ex
);
}
if
(
ex
instanceof
StaleObjectStateException
)
{
return
new
HibernateOptimisticLockingFailureException
((
StaleObjectStateException
)
ex
);
}
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java
浏览文件 @
76369137
...
...
@@ -173,8 +173,8 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
* Returns:
* <ul>
* <li>0 if the two conditions have the same number of expressions
* <li>Less than
1
if "this" has more or more specific media type expressions
* <li>Greater than
1
if "other" has more or more specific media type expressions
* <li>Less than
0
if "this" has more or more specific media type expressions
* <li>Greater than
0
if "other" has more or more specific media type expressions
* </ul>
*
* <p>It is assumed that both instances have been obtained via
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java
浏览文件 @
76369137
...
...
@@ -114,8 +114,8 @@ public final class HeadersRequestCondition extends AbstractRequestCondition<Head
* Returns:
* <ul>
* <li>0 if the two conditions have the same number of header expressions
* <li>Less than
1
if "this" instance has more header expressions
* <li>Greater than
1
if the "other" instance has more header expressions
* <li>Less than
0
if "this" instance has more header expressions
* <li>Greater than
0
if the "other" instance has more header expressions
* </ul>
*
* <p>It is assumed that both instances have been obtained via
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java
浏览文件 @
76369137
...
...
@@ -105,8 +105,8 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
* Returns:
* <ul>
* <li>0 if the two conditions have the same number of parameter expressions
* <li>Less than
1
if "this" instance has more parameter expressions
* <li>Greater than
1
if the "other" instance has more parameter expressions
* <li>Less than
0
if "this" instance has more parameter expressions
* <li>Greater than
0
if the "other" instance has more parameter expressions
* </ul>
*
* <p>It is assumed that both instances have been obtained via
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java
浏览文件 @
76369137
...
...
@@ -111,8 +111,8 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
* Returns:
* <ul>
* <li>0 if the two conditions contain the same number of HTTP request methods.
* <li>Less than
1
if "this" instance has an HTTP request method but "other" doesn't.
* <li>Greater than
1
"other" has an HTTP request method but "this" doesn't.
* <li>Less than
0
if "this" instance has an HTTP request method but "other" doesn't.
* <li>Greater than
0
"other" has an HTTP request method but "this" doesn't.
* </ul>
*
* <p>It is assumed that both instances have been obtained via
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java
浏览文件 @
76369137
...
...
@@ -21,6 +21,8 @@ import org.springframework.web.context.request.NativeWebRequest;
import
org.springframework.web.method.support.HandlerMethodReturnValueHandler
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.SmartView
;
import
org.springframework.web.servlet.View
;
/**
* Handles return values of type {@link ModelAndView} copying view and model
...
...
@@ -48,17 +50,29 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
MethodParameter
returnType
,
ModelAndViewContainer
mavContainer
,
NativeWebRequest
webRequest
)
throws
Exception
{
if
(
returnValue
!=
null
)
{
ModelAndView
mav
=
(
ModelAndView
)
returnValue
;
mavContainer
.
setViewName
(
mav
.
getViewName
());
if
(!
mav
.
isReference
())
{
mavContainer
.
setView
(
mav
.
getView
());
if
(
returnValue
==
null
)
{
mavContainer
.
setRequestHandled
(
true
);
return
;
}
ModelAndView
mav
=
(
ModelAndView
)
returnValue
;
if
(
mav
.
isReference
())
{
String
viewName
=
mav
.
getViewName
();
mavContainer
.
setViewName
(
viewName
);
if
(
viewName
!=
null
&&
viewName
.
startsWith
(
"redirect:"
))
{
mavContainer
.
setRedirectModelScenario
(
true
);
}
mavContainer
.
addAllAttributes
(
mav
.
getModel
());
}
else
{
mavContainer
.
setRequestHandled
(
true
);
View
view
=
mav
.
getView
();
mavContainer
.
setView
(
view
);
if
(
view
instanceof
SmartView
)
{
if
(((
SmartView
)
view
).
isRedirectView
())
{
mavContainer
.
setRedirectModelScenario
(
true
);
}
}
}
mavContainer
.
addAllAttributes
(
mav
.
getModel
());
}
}
\ No newline at end of file
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandlerTests.java
浏览文件 @
76369137
...
...
@@ -18,6 +18,8 @@ package org.springframework.web.servlet.mvc.method.annotation;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotSame
;
import
static
org
.
junit
.
Assert
.
assertSame
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.lang.reflect.Method
;
...
...
@@ -26,10 +28,11 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.method.support.ModelAndViewContainer
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.
method.annotation.ModelAndViewMethodReturnValueHandler
;
import
org.springframework.web.servlet.mvc.
support.RedirectAttributesModelMap
;
import
org.springframework.web.servlet.view.RedirectView
;
/**
...
...
@@ -45,44 +48,90 @@ public class ModelAndViewMethodReturnValueHandlerTests {
private
ServletWebRequest
webRequest
;
private
MethodParameter
returnParamModelAndView
;
@Before
public
void
setUp
()
{
public
void
setUp
()
throws
Exception
{
this
.
handler
=
new
ModelAndViewMethodReturnValueHandler
();
this
.
mavContainer
=
new
ModelAndViewContainer
();
this
.
webRequest
=
new
ServletWebRequest
(
new
MockHttpServletRequest
());
this
.
returnParamModelAndView
=
getReturnValueParam
(
"modelAndView"
);
}
@Test
public
void
supportsReturnType
()
throws
Exception
{
assertTrue
(
handler
.
supportsReturnType
(
getReturnValueParam
(
"modelAndView"
)
));
assertTrue
(
handler
.
supportsReturnType
(
returnParamModelAndView
));
assertFalse
(
handler
.
supportsReturnType
(
getReturnValueParam
(
"viewName"
)));
}
@Test
public
void
handle
ReturnValueViewNam
e
()
throws
Exception
{
public
void
handle
ViewReferenc
e
()
throws
Exception
{
ModelAndView
mav
=
new
ModelAndView
(
"viewName"
,
"attrName"
,
"attrValue"
);
handler
.
handleReturnValue
(
mav
,
getReturnValueParam
(
"modelAndView"
)
,
mavContainer
,
webRequest
);
handler
.
handleReturnValue
(
mav
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
assertEquals
(
"viewName"
,
mavContainer
.
getView
());
assertEquals
(
"attrValue"
,
mavContainer
.
getModel
().
get
(
"attrName"
));
}
@Test
public
void
handle
ReturnValueView
()
throws
Exception
{
public
void
handle
ViewInstance
()
throws
Exception
{
ModelAndView
mav
=
new
ModelAndView
(
new
RedirectView
(),
"attrName"
,
"attrValue"
);
handler
.
handleReturnValue
(
mav
,
getReturnValueParam
(
"modelAndView"
)
,
mavContainer
,
webRequest
);
handler
.
handleReturnValue
(
mav
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
assertEquals
(
RedirectView
.
class
,
mavContainer
.
getView
().
getClass
());
assertEquals
(
"attrValue"
,
mavContainer
.
getModel
().
get
(
"attrName"
));
}
@Test
public
void
handle
ReturnValue
Null
()
throws
Exception
{
handler
.
handleReturnValue
(
null
,
getReturnValueParam
(
"modelAndView"
)
,
mavContainer
,
webRequest
);
public
void
handleNull
()
throws
Exception
{
handler
.
handleReturnValue
(
null
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
assertTrue
(
mavContainer
.
isRequestHandled
());
}
@Test
public
void
handleRedirectAttributesWithViewReference
()
throws
Exception
{
RedirectAttributesModelMap
redirectAttributes
=
new
RedirectAttributesModelMap
();
mavContainer
.
setRedirectModel
(
redirectAttributes
);
ModelAndView
mav
=
new
ModelAndView
(
new
RedirectView
(),
"attrName"
,
"attrValue"
);
handler
.
handleReturnValue
(
mav
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
assertEquals
(
RedirectView
.
class
,
mavContainer
.
getView
().
getClass
());
assertEquals
(
"attrValue"
,
mavContainer
.
getModel
().
get
(
"attrName"
));
assertSame
(
"RedirectAttributes should be used if controller redirects"
,
redirectAttributes
,
mavContainer
.
getModel
());
}
@Test
public
void
handleRedirectAttributesWithViewInstance
()
throws
Exception
{
RedirectAttributesModelMap
redirectAttributes
=
new
RedirectAttributesModelMap
();
mavContainer
.
setRedirectModel
(
redirectAttributes
);
ModelAndView
mav
=
new
ModelAndView
(
"redirect:viewName"
,
"attrName"
,
"attrValue"
);
handler
.
handleReturnValue
(
mav
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
ModelMap
model
=
mavContainer
.
getModel
();
assertEquals
(
"redirect:viewName"
,
mavContainer
.
getViewName
());
assertEquals
(
"attrValue"
,
model
.
get
(
"attrName"
));
assertSame
(
"RedirectAttributes should be used if controller redirects"
,
redirectAttributes
,
model
);
}
@Test
public
void
handleRedirectAttributesWithoutRedirect
()
throws
Exception
{
RedirectAttributesModelMap
redirectAttributes
=
new
RedirectAttributesModelMap
();
mavContainer
.
setRedirectModel
(
redirectAttributes
);
ModelAndView
mav
=
new
ModelAndView
();
handler
.
handleReturnValue
(
mav
,
returnParamModelAndView
,
mavContainer
,
webRequest
);
ModelMap
model
=
mavContainer
.
getModel
();
assertEquals
(
null
,
mavContainer
.
getView
());
assertTrue
(
mavContainer
.
getModel
().
isEmpty
());
assertNotSame
(
"RedirectAttributes should not be used if controller doesn't redirect"
,
redirectAttributes
,
model
);
}
private
MethodParameter
getReturnValueParam
(
String
methodName
)
throws
Exception
{
Method
method
=
getClass
().
getDeclaredMethod
(
methodName
);
return
new
MethodParameter
(
method
,
-
1
);
...
...
spring-framework-reference/src/view.xml
浏览文件 @
76369137
...
...
@@ -707,6 +707,10 @@ productList.url=/WEB-INF/jsp/productlist.jsp</programlisting>
<para><literal>
path="lastName"
</literal>
- displays all errors
associated with the
<literal>
lastName
</literal>
field
</para>
</listitem>
<listitem>
<para>
if
<literal>
path
</literal>
is omitted - object errors only are displayed
</para>
</listitem>
</itemizedlist>
<para>
The example below will display a list of errors at the top of
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录