Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
acc84925
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,发现更多精彩内容 >>
提交
acc84925
编写于
4月 17, 2009
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-5631 - Implicit /** mapping on type-level @RequestMapping
上级
02e96e01
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
30 deletion
+47
-30
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
...rc/main/java/org/springframework/util/AntPathMatcher.java
+8
-14
org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java
...st/java/org/springframework/util/AntPathMatcherTests.java
+1
-0
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
...ervlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
+24
-10
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
...notation/UriTemplateServletAnnotationControllerTests.java
+14
-6
未找到文件。
org.springframework.core/src/main/java/org/springframework/util/AntPathMatcher.java
浏览文件 @
acc84925
...
...
@@ -319,8 +319,7 @@ public class AntPathMatcher implements PathMatcher {
}
else
{
int
dotPos1
=
pattern1
.
indexOf
(
'.'
);
int
dotPos2
=
pattern2
.
indexOf
(
'.'
);
if
(
dotPos1
==
-
1
&&
dotPos2
==
-
1
)
{
if
(
dotPos1
==
-
1
)
{
// simply concatenate the two patterns
if
(
pattern1
.
endsWith
(
"/"
)
||
pattern2
.
startsWith
(
"/"
))
{
return
pattern1
+
pattern2
;
...
...
@@ -329,25 +328,20 @@ public class AntPathMatcher implements PathMatcher {
return
pattern1
+
"/"
+
pattern2
;
}
}
String
fileName1
=
""
;
String
extension1
=
""
;
if
(
dotPos1
!=
-
1
)
{
fileName1
=
pattern1
.
substring
(
0
,
dotPos1
);
extension1
=
pattern1
.
substring
(
dotPos1
);
}
else
{
fileName1
=
pattern1
;
}
String
fileName2
=
""
;
String
extension2
=
""
;
String
fileName1
=
pattern1
.
substring
(
0
,
dotPos1
);
String
extension1
=
pattern1
.
substring
(
dotPos1
);
String
fileName2
;
String
extension2
;
int
dotPos2
=
pattern2
.
indexOf
(
'.'
);
if
(
dotPos2
!=
-
1
)
{
fileName2
=
pattern2
.
substring
(
0
,
dotPos2
);
extension2
=
pattern2
.
substring
(
dotPos2
);
}
else
{
fileName2
=
pattern2
;
extension2
=
""
;
}
String
fileName
=
fileName1
.
endsWith
(
"*"
)
?
fileName2
:
fileName
2
;
String
fileName
=
fileName1
.
endsWith
(
"*"
)
?
fileName2
:
fileName
1
;
String
extension
=
extension1
.
startsWith
(
"*"
)
?
extension2
:
extension1
;
return
fileName
+
extension
;
...
...
org.springframework.core/src/test/java/org/springframework/util/AntPathMatcherTests.java
浏览文件 @
acc84925
...
...
@@ -348,6 +348,7 @@ public class AntPathMatcherTests {
assertEquals
(
"/hotels/{hotel}"
,
pathMatcher
.
combine
(
"/hotels/*"
,
"{hotel}"
));
assertEquals
(
"/hotels/**/{hotel}"
,
pathMatcher
.
combine
(
"/hotels/**"
,
"{hotel}"
));
assertEquals
(
"/hotels/{hotel}"
,
pathMatcher
.
combine
(
"/hotels"
,
"{hotel}"
));
assertEquals
(
"/hotels/{hotel}.*"
,
pathMatcher
.
combine
(
"/hotels"
,
"{hotel}.*"
));
assertEquals
(
"/hotels/*/booking/{booking}"
,
pathMatcher
.
combine
(
"/hotels/*/booking"
,
"{booking}"
));
assertEquals
(
"/hotel.html"
,
pathMatcher
.
combine
(
"/*.html"
,
"/hotel.html"
));
assertEquals
(
"/hotel.html"
,
pathMatcher
.
combine
(
"/*.html"
,
"/hotel"
));
...
...
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
浏览文件 @
acc84925
...
...
@@ -399,11 +399,11 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
boolean
match
=
false
;
if
(
mappingInfo
.
paths
.
length
>
0
)
{
List
<
String
>
matchedPaths
=
new
ArrayList
<
String
>(
mappingInfo
.
paths
.
length
);
for
(
String
m
appedPath
:
mappingInfo
.
paths
)
{
if
(
isPathMatch
(
m
appedPath
,
lookupPath
))
{
for
(
String
m
ethodLevelPattern
:
mappingInfo
.
paths
)
{
if
(
isPathMatch
(
m
ethodLevelPattern
,
lookupPath
))
{
if
(
checkParameters
(
mappingInfo
,
request
))
{
match
=
true
;
matchedPaths
.
add
(
m
appedPath
);
matchedPaths
.
add
(
m
ethodLevelPattern
);
}
else
{
for
(
RequestMethod
requestMethod
:
mappingInfo
.
methods
)
{
...
...
@@ -479,17 +479,31 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
}
}
private
boolean
isPathMatch
(
String
m
appedPath
,
String
lookupPath
)
{
if
(
mappedPath
.
equals
(
lookupPath
)
||
pathMatcher
.
match
(
mappedPath
,
lookupPath
))
{
private
boolean
isPathMatch
(
String
m
ethodLevelPattern
,
String
lookupPath
)
{
if
(
isPathMatchInternal
(
methodLevelPattern
,
lookupPath
))
{
return
true
;
}
boolean
hasSuffix
=
(
mappedPath
.
indexOf
(
'.'
)
!=
-
1
);
if
(!
hasSuffix
&&
pathMatcher
.
match
(
mappedPath
+
".*"
,
lookupPath
))
{
if
(
hasTypeLevelMapping
())
{
String
[]
typeLevelPatterns
=
getTypeLevelMapping
().
value
();
for
(
String
typeLevelPattern
:
typeLevelPatterns
)
{
if
(!
typeLevelPattern
.
startsWith
(
"/"
))
{
typeLevelPattern
=
"/"
+
typeLevelPattern
;
}
String
combinedPattern
=
pathMatcher
.
combine
(
typeLevelPattern
,
methodLevelPattern
);
if
(
isPathMatchInternal
(
combinedPattern
,
lookupPath
))
{
return
true
;
}
}
}
return
false
;
}
private
boolean
isPathMatchInternal
(
String
pattern
,
String
lookupPath
)
{
if
(
pattern
.
equals
(
lookupPath
)
||
pathMatcher
.
match
(
pattern
,
lookupPath
))
{
return
true
;
}
return
(!
mappedPath
.
startsWith
(
"/"
)
&&
(
lookupPath
.
endsWith
(
mappedPath
)
||
pathMatcher
.
match
(
"/**/"
+
mappedPath
,
lookupPath
)
||
(!
hasSuffix
&&
pathMatcher
.
match
(
"/**/"
+
mappedPath
+
".*"
,
lookupPath
))));
return
!(
pattern
.
indexOf
(
'.'
)
!=
-
1
)
&&
pathMatcher
.
match
(
pattern
+
".*"
,
lookupPath
);
}
private
boolean
checkParameters
(
RequestMappingInfo
mapping
,
HttpServletRequest
request
)
{
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/UriTemplateServletAnnotationControllerTests.java
浏览文件 @
acc84925
...
...
@@ -24,7 +24,6 @@ import javax.servlet.ServletException;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.springframework.beans.BeansException
;
...
...
@@ -145,24 +144,33 @@ public class UriTemplateServletAnnotationControllerTests {
}
@Test
@Ignore
(
"In progress"
)
public
void
crud
()
throws
Exception
{
initServlet
(
CrudController
.
class
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"
getHotels
"
,
response
.
getContentAsString
());
assertEquals
(
"
list
"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"POST"
,
"/hotels"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"
newHotel
"
,
response
.
getContentAsString
());
assertEquals
(
"
create
"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"POST"
,
"/hotels"
);
request
=
new
MockHttpServletRequest
(
"GET"
,
"/hotels/42"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"show-42"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"PUT"
,
"/hotels/42"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"createOrUpdate-42"
,
response
.
getContentAsString
());
request
=
new
MockHttpServletRequest
(
"DELETE"
,
"/hotels/42"
);
response
=
new
MockHttpServletResponse
();
servlet
.
service
(
request
,
response
);
assertEquals
(
"
newHotel
"
,
response
.
getContentAsString
());
assertEquals
(
"
remove-42
"
,
response
.
getContentAsString
());
}
private
void
initServlet
(
final
Class
<?>
controllerclass
)
throws
ServletException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录