Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d75f1287
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,发现更多精彩内容 >>
提交
d75f1287
编写于
9月 04, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
86b7118d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
39 deletion
+28
-39
spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java
...amework/http/converter/json/GsonHttpMessageConverter.java
+1
-1
spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java
...pringframework/web/bind/support/WebRequestDataBinder.java
+12
-24
spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java
...ork/web/servlet/config/ResourcesBeanDefinitionParser.java
+2
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java
...amework/web/servlet/resource/VersionResourceResolver.java
+13
-12
未找到文件。
spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java
浏览文件 @
d75f1287
...
...
@@ -204,7 +204,7 @@ public class GsonHttpMessageConverter extends AbstractHttpMessageConverter<Objec
this
.
gson
.
toJson
(
o
,
writer
);
writer
.
close
();
}
catch
(
JsonIOException
ex
)
{
catch
(
JsonIOException
ex
)
{
throw
new
HttpMessageNotWritableException
(
"Could not write JSON: "
+
ex
.
getMessage
(),
ex
);
}
}
...
...
spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java
浏览文件 @
d75f1287
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
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,11 +16,8 @@
package
org.springframework.web.bind.support
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.Part
;
...
...
@@ -73,7 +70,6 @@ import org.springframework.web.multipart.MultipartRequest;
*/
public
class
WebRequestDataBinder
extends
WebDataBinder
{
/**
* Create a new WebRequestDataBinder instance, with default object name.
* @param target the target object to bind onto (or {@code null}
...
...
@@ -115,8 +111,7 @@ public class WebRequestDataBinder extends WebDataBinder {
*/
public
void
bind
(
WebRequest
request
)
{
MutablePropertyValues
mpvs
=
new
MutablePropertyValues
(
request
.
getParameterMap
());
if
(
isMultipartRequest
(
request
)
&&
(
request
instanceof
NativeWebRequest
))
{
if
(
isMultipartRequest
(
request
)
&&
request
instanceof
NativeWebRequest
)
{
MultipartRequest
multipartRequest
=
((
NativeWebRequest
)
request
).
getNativeRequest
(
MultipartRequest
.
class
);
if
(
multipartRequest
!=
null
)
{
bindMultipart
(
multipartRequest
.
getMultiFileMap
(),
mpvs
);
...
...
@@ -129,6 +124,15 @@ public class WebRequestDataBinder extends WebDataBinder {
doBind
(
mpvs
);
}
/**
* Check if the request is a multipart request (by checking its Content-Type header).
* @param request request with parameters to bind
*/
private
boolean
isMultipartRequest
(
WebRequest
request
)
{
String
contentType
=
request
.
getHeader
(
"Content-Type"
);
return
(
contentType
!=
null
&&
StringUtils
.
startsWithIgnoreCase
(
contentType
,
"multipart"
));
}
/**
* Treats errors as fatal.
* <p>Use this method only if it's an error if the input isn't valid.
...
...
@@ -141,16 +145,6 @@ public class WebRequestDataBinder extends WebDataBinder {
}
}
/**
* Check if the request is a multipart request (by checking its Content-Type header).
*
* @param request request with parameters to bind
*/
private
boolean
isMultipartRequest
(
WebRequest
request
)
{
String
contentType
=
request
.
getHeader
(
"Content-Type"
);
return
((
contentType
!=
null
)
&&
StringUtils
.
startsWithIgnoreCase
(
contentType
,
"multipart"
));
}
/**
* Encapsulate Part binding code for Servlet 3.0+ only containers.
...
...
@@ -160,12 +154,10 @@ public class WebRequestDataBinder extends WebDataBinder {
private
final
boolean
bindEmptyMultipartFiles
;
public
Servlet3MultipartHelper
(
boolean
bindEmptyMultipartFiles
)
{
this
.
bindEmptyMultipartFiles
=
bindEmptyMultipartFiles
;
}
public
void
bindParts
(
HttpServletRequest
request
,
MutablePropertyValues
mpvs
)
{
try
{
MultiValueMap
<
String
,
Part
>
map
=
new
LinkedMultiValueMap
<
String
,
Part
>();
...
...
@@ -184,14 +176,10 @@ public class WebRequestDataBinder extends WebDataBinder {
}
}
}
catch
(
IOException
ex
)
{
throw
new
MultipartException
(
"Failed to get request parts"
,
ex
);
}
catch
(
ServletException
ex
)
{
catch
(
Exception
ex
)
{
throw
new
MultipartException
(
"Failed to get request parts"
,
ex
);
}
}
}
}
spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java
浏览文件 @
d75f1287
...
...
@@ -99,7 +99,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
handlerMappingDef
.
getPropertyValues
().
add
(
"pathMatcher"
,
pathMatcherRef
).
add
(
"urlPathHelper"
,
pathHelperRef
);
String
order
=
element
.
getAttribute
(
"order"
);
//
u
se a default of near-lowest precedence, still allowing for even lower precedence in other mappings
//
U
se a default of near-lowest precedence, still allowing for even lower precedence in other mappings
handlerMappingDef
.
getPropertyValues
().
add
(
"order"
,
StringUtils
.
hasText
(
order
)
?
order
:
Ordered
.
LOWEST_PRECEDENCE
-
1
);
String
beanName
=
parserContext
.
getReaderContext
().
generateBeanName
(
handlerMappingDef
);
...
...
@@ -278,7 +278,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
Element
childElement
=
DomUtils
.
getChildElementsByTagName
(
beanElement
,
"bean"
,
"ref"
).
get
(
0
);
strategy
=
parserContext
.
getDelegate
().
parsePropertySubElement
(
childElement
,
null
);
}
for
(
String
pattern
:
patterns
)
{
for
(
String
pattern
:
patterns
)
{
strategyMap
.
put
(
pattern
,
strategy
);
}
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java
浏览文件 @
d75f1287
...
...
@@ -15,8 +15,12 @@
*/
package
org.springframework.web.servlet.resource
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.core.io.Resource
;
...
...
@@ -56,12 +60,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
/**
* Set a Map with URL paths as keys and {@code VersionStrategy}
* as values.
*
* Set a Map with URL paths as keys and {@code VersionStrategy} as values.
* <p>Supports direct URL matches and Ant-style pattern matches. For syntax
* details, see the {@link org.springframework.util.AntPathMatcher} javadoc.
*
* @param map map with URLs as keys and version strategies as values
*/
public
void
setStrategyMap
(
Map
<
String
,
VersionStrategy
>
map
)
{
...
...
@@ -118,7 +119,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
* @see VersionStrategy
*/
public
VersionResourceResolver
addVersionStrategy
(
VersionStrategy
strategy
,
String
...
pathPatterns
)
{
for
(
String
pattern
:
pathPatterns
)
{
for
(
String
pattern
:
pathPatterns
)
{
getStrategyMap
().
put
(
pattern
,
strategy
);
}
return
this
;
...
...
@@ -148,7 +149,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
}
String
simplePath
=
versionStrategy
.
removeVersion
(
requestPath
,
candidateVersion
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Extracted version from path, re-resolving without version, path=\""
+
simplePath
+
"\""
);
}
...
...
@@ -166,8 +166,10 @@ public class VersionResourceResolver extends AbstractResourceResolver {
return
baseResource
;
}
else
{
logger
.
trace
(
"Potential resource found for ["
+
requestPath
+
"], but version ["
+
candidateVersion
+
"] doesn't match."
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Potential resource found for ["
+
requestPath
+
"], but version ["
+
candidateVersion
+
"] doesn't match."
);
}
return
null
;
}
}
...
...
@@ -194,7 +196,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
}
/**
* Find
s
a {@code VersionStrategy} for the request path of the requested resource.
* Find a {@code VersionStrategy} for the request path of the requested resource.
* @return an instance of a {@code VersionStrategy} or null if none matches that request path
*/
protected
VersionStrategy
getStrategyForPath
(
String
requestPath
)
{
...
...
@@ -210,7 +212,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
Collections
.
sort
(
matchingPatterns
,
comparator
);
return
this
.
versionStrategyMap
.
get
(
matchingPatterns
.
get
(
0
));
}
return
null
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录