Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
205e5dfd
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,体验更适合开发者的 AI 搜索 >>
提交
205e5dfd
编写于
5月 04, 2015
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support bridged methods in MvcUriComponentsBuilder
Issue: SPR-12977
上级
9637b12f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
25 deletion
+29
-25
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java
...ervlet/mvc/method/annotation/MvcUriComponentsBuilder.java
+20
-14
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java
...t/mvc/method/annotation/MvcUriComponentsBuilderTests.java
+9
-11
未找到文件。
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java
浏览文件 @
205e5dfd
...
@@ -21,6 +21,7 @@ import java.util.Arrays;
...
@@ -21,6 +21,7 @@ import java.util.Arrays;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -49,6 +50,7 @@ import org.springframework.util.Assert;
...
@@ -49,6 +50,7 @@ import org.springframework.util.Assert;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.PathMatcher
;
import
org.springframework.util.PathMatcher
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.ReflectionUtils.MethodFilter
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
...
@@ -56,6 +58,7 @@ import org.springframework.web.context.request.RequestAttributes;
...
@@ -56,6 +58,7 @@ import org.springframework.web.context.request.RequestAttributes;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.HandlerMethodSelector
;
import
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver
;
import
org.springframework.web.method.annotation.RequestParamMethodArgumentResolver
;
import
org.springframework.web.method.support.CompositeUriComponentsContributor
;
import
org.springframework.web.method.support.CompositeUriComponentsContributor
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
...
@@ -412,25 +415,28 @@ public class MvcUriComponentsBuilder {
...
@@ -412,25 +415,28 @@ public class MvcUriComponentsBuilder {
return
paths
[
0
];
return
paths
[
0
];
}
}
private
static
Method
getMethod
(
Class
<?>
controllerType
,
final
String
methodName
,
final
Object
...
args
)
{
private
static
Method
getMethod
(
Class
<?>
controllerType
,
String
methodName
,
Object
...
args
)
{
MethodFilter
selector
=
new
MethodFilter
()
{
Method
match
=
null
;
@Override
for
(
Method
method
:
controllerType
.
getDeclaredMethods
())
{
public
boolean
matches
(
Method
method
)
{
if
(
method
.
getName
().
equals
(
methodName
)
&&
method
.
getParameterTypes
().
length
==
args
.
length
)
{
String
name
=
method
.
getName
();
if
(
match
!=
null
)
{
int
argLength
=
method
.
getParameterTypes
().
length
;
throw
new
IllegalArgumentException
(
String
.
format
(
return
(
name
.
equals
(
methodName
)
&&
argLength
==
args
.
length
);
"Found two methods named '%s' accepting arguments %s in controller %s: [%s] and [%s]"
,
methodName
,
Arrays
.
asList
(
args
),
controllerType
.
getName
(),
match
.
toGenericString
(),
method
.
toGenericString
()));
}
match
=
method
;
}
}
};
Set
<
Method
>
methods
=
HandlerMethodSelector
.
selectMethods
(
controllerType
,
selector
);
if
(
methods
.
size
()
==
1
)
{
return
methods
.
iterator
().
next
();
}
}
if
(
match
==
null
)
{
else
if
(
methods
.
size
()
>
1
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Found two methods named '%s' accepting arguments %s in controller %s: [%s]"
,
methodName
,
Arrays
.
asList
(
args
),
controllerType
.
getName
(),
methods
));
}
else
{
throw
new
IllegalArgumentException
(
"No method named '"
+
methodName
+
"' with "
+
args
.
length
+
throw
new
IllegalArgumentException
(
"No method named '"
+
methodName
+
"' with "
+
args
.
length
+
" arguments found in controller "
+
controllerType
.
getName
());
" arguments found in controller "
+
controllerType
.
getName
());
}
}
return
match
;
}
}
private
static
UriComponents
applyContributors
(
UriComponentsBuilder
builder
,
Method
method
,
Object
...
args
)
{
private
static
UriComponents
applyContributors
(
UriComponentsBuilder
builder
,
Method
method
,
Object
...
args
)
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilderTests.java
浏览文件 @
205e5dfd
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
package
org.springframework.web.servlet.mvc.method.annotation
;
package
org.springframework.web.servlet.mvc.method.annotation
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
web
.
servlet
.
mvc
.
method
.
annotation
.
MvcUriComponentsBuilder
.*;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
...
@@ -25,13 +29,10 @@ import java.util.Arrays;
...
@@ -25,13 +29,10 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.List
;
import
org.hamcrest.Matchers
;
import
org.hamcrest.Matchers
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTime
;
import
org.joda.time.format.ISODateTimeFormat
;
import
org.joda.time.format.ISODateTimeFormat
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -57,10 +58,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
...
@@ -57,10 +58,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import
org.springframework.web.util.UriComponents
;
import
org.springframework.web.util.UriComponents
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
springframework
.
web
.
servlet
.
mvc
.
method
.
annotation
.
MvcUriComponentsBuilder
.*;
/**
/**
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
* Unit tests for {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
*
*
...
@@ -69,6 +66,7 @@ import static org.springframework.web.servlet.mvc.method.annotation.MvcUriCompon
...
@@ -69,6 +66,7 @@ import static org.springframework.web.servlet.mvc.method.annotation.MvcUriCompon
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
* @author Sam Brannen
* @author Sam Brannen
*/
*/
@SuppressWarnings
(
"unused"
)
public
class
MvcUriComponentsBuilderTests
{
public
class
MvcUriComponentsBuilderTests
{
private
final
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
private
final
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
...
@@ -172,12 +170,12 @@ public class MvcUriComponentsBuilderTests {
...
@@ -172,12 +170,12 @@ public class MvcUriComponentsBuilderTests {
assertThat
(
queryParams
.
get
(
"offset"
),
contains
(
"10"
));
assertThat
(
queryParams
.
get
(
"offset"
),
contains
(
"10"
));
}
}
// SPR-12977
@Test
@Test
// TODO [SPR-12977] Enable fromMethodNameWithBridgedMethod() test.
@Ignore
(
"Disabled until SPR-12977 is resolved"
)
public
void
fromMethodNameWithBridgedMethod
()
throws
Exception
{
public
void
fromMethodNameWithBridgedMethod
()
throws
Exception
{
UriComponents
uriComponents
=
fromMethodName
(
PersonCrudController
.
class
,
"get"
,
new
Long
(
42
)
).
build
();
UriComponents
uriComponents
=
fromMethodName
(
PersonCrudController
.
class
,
"get"
,
(
long
)
42
).
build
();
assertThat
(
uriComponents
.
toUriString
(),
is
(
"http://localhost/
get/
42"
));
assertThat
(
uriComponents
.
toUriString
(),
is
(
"http://localhost/42"
));
}
}
// SPR-11391
// SPR-11391
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录