Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
19c2672d
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,发现更多精彩内容 >>
提交
19c2672d
编写于
7月 27, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polishing
上级
f4adf227
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
64 deletion
+59
-64
org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
...ework/jdbc/datasource/init/ResourceDatabasePopulator.java
+25
-13
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
...ervlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
+21
-27
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
...notation/UriTemplateServletAnnotationControllerTests.java
+13
-24
未找到文件。
org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
浏览文件 @
19c2672d
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
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.
...
...
@@ -50,6 +50,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
private
static
final
Log
logger
=
LogFactory
.
getLog
(
ResourceDatabasePopulator
.
class
);
private
List
<
Resource
>
scripts
=
new
ArrayList
<
Resource
>();
private
String
sqlScriptEncoding
;
...
...
@@ -62,6 +63,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
private
String
separator
=
null
;
/**
* @param separator the statement separator
*/
...
...
@@ -121,6 +123,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
this
.
ignoreFailedDrops
=
ignoreFailedDrops
;
}
public
void
populate
(
Connection
connection
)
throws
SQLException
{
for
(
Resource
script
:
this
.
scripts
)
{
executeSqlScript
(
connection
,
applyEncodingIfNecessary
(
script
),
this
.
continueOnError
,
this
.
ignoreFailedDrops
);
...
...
@@ -130,7 +133,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
private
EncodedResource
applyEncodingIfNecessary
(
Resource
script
)
{
if
(
script
instanceof
EncodedResource
)
{
return
(
EncodedResource
)
script
;
}
else
{
}
else
{
return
new
EncodedResource
(
script
,
this
.
sqlScriptEncoding
);
}
}
...
...
@@ -177,22 +181,26 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
rowsAffected
+
" rows affected by SQL: "
+
statement
);
}
}
catch
(
SQLException
ex
)
{
}
catch
(
SQLException
ex
)
{
boolean
dropStatement
=
StringUtils
.
startsWithIgnoreCase
(
statement
.
trim
(),
"drop"
);
if
(
continueOnError
||
(
dropStatement
&&
ignoreFailedDrops
))
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Failed to execute SQL script statement at line "
+
lineNumber
+
" of resource "
+
resource
+
": "
+
statement
,
ex
);
}
}
else
{
}
else
{
throw
new
ScriptStatementFailedException
(
statement
,
lineNumber
,
resource
,
ex
);
}
}
}
}
finally
{
}
finally
{
try
{
stmt
.
close
();
}
catch
(
Throwable
ex
)
{
}
catch
(
Throwable
ex
)
{
logger
.
debug
(
"Could not close JDBC Statement"
,
ex
);
}
}
...
...
@@ -213,8 +221,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
String
currentStatement
=
lnr
.
readLine
();
StringBuilder
scriptBuilder
=
new
StringBuilder
();
while
(
currentStatement
!=
null
)
{
if
(
StringUtils
.
hasText
(
currentStatement
)
&&
(
this
.
commentPrefix
!=
null
&&
!
currentStatement
.
startsWith
(
this
.
commentPrefix
)
))
{
if
(
StringUtils
.
hasText
(
currentStatement
)
&&
this
.
commentPrefix
!=
null
&&
!
currentStatement
.
startsWith
(
this
.
commentPrefix
))
{
if
(
scriptBuilder
.
length
()
>
0
)
{
scriptBuilder
.
append
(
'\n'
);
}
...
...
@@ -227,13 +235,16 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
}
private
void
maybeAddSeparatorToScript
(
StringBuilder
scriptBuilder
)
{
if
(
separator
==
null
||
separator
.
trim
().
length
()==
separator
.
length
())
{
if
(
this
.
separator
==
null
)
{
return
;
}
String
trimmed
=
this
.
separator
.
trim
();
if
(
trimmed
.
length
()
==
this
.
separator
.
length
())
{
return
;
}
String
trimmed
=
separator
.
trim
();
// separator ends in whitespace, so we might want to see if the script is trying to end the same way
if
(
scriptBuilder
.
lastIndexOf
(
trimmed
)
==
scriptBuilder
.
length
()-
trimmed
.
length
())
{
scriptBuilder
.
append
(
separator
.
substring
(
trimmed
.
length
()));
if
(
scriptBuilder
.
lastIndexOf
(
trimmed
)
==
scriptBuilder
.
length
()
-
trimmed
.
length
())
{
scriptBuilder
.
append
(
this
.
separator
.
substring
(
trimmed
.
length
()));
}
}
...
...
@@ -292,7 +303,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
}
i
+=
delim
.
length
()
-
1
;
continue
;
}
else
if
(
c
==
'\n'
||
c
==
'\t'
)
{
}
else
if
(
c
==
'\n'
||
c
==
'\t'
)
{
c
=
' '
;
}
}
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
浏览文件 @
19c2672d
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
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.
...
...
@@ -27,7 +27,6 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
...
...
@@ -105,19 +104,16 @@ import org.springframework.web.context.request.NativeWebRequest;
import
org.springframework.web.context.request.RequestScope
;
import
org.springframework.web.context.request.ServletWebRequest
;
import
org.springframework.web.context.request.WebRequest
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.multipart.MultipartRequest
;
import
org.springframework.web.servlet.HandlerAdapter
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.mvc.LastModified
;
import
org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver
;
import
org.springframework.web.servlet.mvc.multiaction.MethodNameResolver
;
import
org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException
;
import
org.springframework.web.servlet.support.RequestContextUtils
;
import
org.springframework.web.servlet.support.WebContentGenerator
;
import
org.springframework.web.util.UriTemplate
;
import
org.springframework.web.util.UrlPathHelper
;
import
org.springframework.web.util.WebUtils
;
...
...
@@ -663,11 +659,9 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
}
else
{
if
(!
allowedMethods
.
isEmpty
())
{
throw
new
HttpRequestMethodNotSupportedException
(
request
.
getMethod
(),
StringUtils
.
toStringArray
(
allowedMethods
));
throw
new
HttpRequestMethodNotSupportedException
(
request
.
getMethod
(),
StringUtils
.
toStringArray
(
allowedMethods
));
}
throw
new
NoSuchRequestHandlingMethodException
(
lookupPath
,
request
.
getMethod
(),
request
.
getParameterMap
());
throw
new
NoSuchRequestHandlingMethodException
(
lookupPath
,
request
.
getMethod
(),
request
.
getParameterMap
());
}
}
...
...
@@ -675,17 +669,17 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
if
(!
hasTypeLevelMapping
()
||
ObjectUtils
.
isEmpty
(
getTypeLevelMapping
().
value
()))
{
return
false
;
}
return
(
Boolean
)
request
.
getAttribute
(
HandlerMapping
.
INTROSPECT_TYPE_LEVEL_MAPPING
);
return
(
Boolean
)
request
.
getAttribute
(
HandlerMapping
.
INTROSPECT_TYPE_LEVEL_MAPPING
);
}
/**
* Determines the combined pattern for the given methodLevelPattern and path.
* <p>Uses the following algorithm: <ol>
* <p>Uses the following algorithm:
* <ol>
* <li>If there is a type-level mapping with path information, it is {@linkplain
* PathMatcher#combine(String, String) combined} with the method-level pattern.</li>
* <li>If there is a {@linkplain HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE best matching pattern}
in the
* request, it is combined with the method-level pattern.</li>
* <li>If there is a {@linkplain HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE best matching pattern}
*
in the
request, it is combined with the method-level pattern.</li>
* <li>Otherwise, the method-level pattern is returned.</li>
* </ol>
*/
...
...
@@ -708,7 +702,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
if
(
StringUtils
.
hasText
(
bestMatchingPattern
)
&&
bestMatchingPattern
.
endsWith
(
"*"
))
{
String
combinedPattern
=
pathMatcher
.
combine
(
bestMatchingPattern
,
methodLevelPattern
);
String
matchingPattern
=
getMatchingPattern
(
combinedPattern
,
lookupPath
);
if
(
(
matchingPattern
!=
null
)
&&
!
matchingPattern
.
equals
(
bestMatchingPattern
))
{
if
(
matchingPattern
!=
null
&&
!
matchingPattern
.
equals
(
bestMatchingPattern
))
{
return
matchingPattern
;
}
}
...
...
@@ -720,31 +714,31 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
return
pattern
;
}
boolean
hasSuffix
=
pattern
.
indexOf
(
'.'
)
!=
-
1
;
if
(!
hasSuffix
&&
pathMatcher
.
match
(
pattern
+
".*"
,
lookupPath
))
{
return
pattern
+
".*"
;
if
(!
hasSuffix
)
{
String
patternWithSuffix
=
pattern
+
".*"
;
if
(
pathMatcher
.
match
(
patternWithSuffix
,
lookupPath
))
{
return
patternWithSuffix
;
}
}
if
(
pathMatcher
.
match
(
pattern
,
lookupPath
))
{
return
pattern
;
}
boolean
endsWithSlash
=
pattern
.
endsWith
(
"/"
);
if
(!
endsWithSlash
&&
pathMatcher
.
match
(
pattern
+
"/"
,
lookupPath
))
{
return
pattern
+
"/"
;
if
(!
endsWithSlash
)
{
String
patternWithSlash
=
pattern
+
"/"
;
if
(
pathMatcher
.
match
(
patternWithSlash
,
lookupPath
))
{
return
patternWithSlash
;
}
}
return
null
;
}
@SuppressWarnings
(
"unchecked"
)
private
void
extractHandlerMethodUriTemplates
(
String
mappedPattern
,
String
lookupPath
,
HttpServletRequest
request
)
{
private
void
extractHandlerMethodUriTemplates
(
String
mappedPattern
,
String
lookupPath
,
HttpServletRequest
request
)
{
Map
<
String
,
String
>
variables
=
(
Map
<
String
,
String
>)
request
.
getAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
);
int
patternVariableCount
=
StringUtils
.
countOccurrencesOf
(
mappedPattern
,
"{"
);
if
(
(
variables
==
null
||
patternVariableCount
!=
variables
.
size
())
&&
pathMatcher
.
match
(
mappedPattern
,
lookupPath
))
{
if
((
variables
==
null
||
patternVariableCount
!=
variables
.
size
())
&&
pathMatcher
.
match
(
mappedPattern
,
lookupPath
))
{
variables
=
pathMatcher
.
extractUriTemplateVariables
(
mappedPattern
,
lookupPath
);
request
.
setAttribute
(
HandlerMapping
.
URI_TEMPLATE_VARIABLES_ATTRIBUTE
,
variables
);
}
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
浏览文件 @
19c2672d
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
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,7 +23,6 @@ import java.util.Date;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.springframework.beans.BeansException
;
...
...
@@ -43,7 +42,12 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
;
/** @author Arjen Poutsma */
import
static
org
.
junit
.
Assert
.*;
/**
* @author Arjen Poutsma
* @author Rossen Stoyanchev
*/
public
class
UriTemplateServletAnnotationControllerTests
{
private
DispatcherServlet
servlet
;
...
...
@@ -309,9 +313,7 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"test-42"
,
response
.
getContentAsString
());
}
/*
* See SPR-6640
*/
// SPR-6640
@Test
public
void
menuTree
()
throws
Exception
{
initServlet
(
MenuTreeController
.
class
);
...
...
@@ -322,9 +324,7 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"M5"
,
response
.
getContentAsString
());
}
/*
* See SPR-6876
*/
// SPR-6876
@Test
public
void
variableNames
()
throws
Exception
{
initServlet
(
VariableNamesController
.
class
);
...
...
@@ -340,9 +340,7 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"bar-bar"
,
response
.
getContentAsString
());
}
/*
* See SPR-8543
*/
// SPR-8543
@Test
public
void
variableNamesWithUrlExtension
()
throws
Exception
{
initServlet
(
VariableNamesController
.
class
);
...
...
@@ -353,9 +351,7 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"foo-foo"
,
response
.
getContentAsString
());
}
/*
* See SPR-6906
*/
// SPR-6906
@Test
public
void
controllerClassName
()
throws
Exception
{
servlet
=
new
DispatcherServlet
()
{
...
...
@@ -389,9 +385,7 @@ public class UriTemplateServletAnnotationControllerTests {
assertEquals
(
"plain-bar"
,
response
.
getContentAsString
());
}
/*
* See SPR-6978
*/
// SPR-6978
@Test
public
void
doIt
()
throws
Exception
{
initServlet
(
Spr6978Controller
.
class
);
...
...
@@ -419,10 +413,7 @@ public class UriTemplateServletAnnotationControllerTests {
}
/*
* Controllers
*/
// Controllers
@Controller
public
static
class
SimpleUriTemplateController
{
...
...
@@ -561,7 +552,6 @@ public class UriTemplateServletAnnotationControllerTests {
}
@Controller
@RequestMapping
(
"hotels"
)
public
static
class
CrudController
{
...
...
@@ -689,5 +679,4 @@ public class UriTemplateServletAnnotationControllerTests {
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录