Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
62565860
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 搜索 >>
提交
62565860
编写于
10月 12, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
4391b299
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
60 addition
and
52 deletion
+60
-52
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java
...mework/http/client/BufferingClientHttpRequestFactory.java
+16
-8
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java
...mework/http/client/BufferingClientHttpRequestWrapper.java
+1
-3
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java
...ework/http/client/BufferingClientHttpResponseWrapper.java
+3
-3
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
...g/springframework/web/bind/annotation/RequestMapping.java
+5
-5
spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java
...mework/web/servlet/view/json/MappingJackson2JsonView.java
+9
-7
src/asciidoc/web-mvc.adoc
src/asciidoc/web-mvc.adoc
+26
-26
未找到文件。
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestFactory.java
浏览文件 @
62565860
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -22,22 +22,30 @@ import java.net.URI;
import
org.springframework.http.HttpMethod
;
/**
* Wrapper for a {@link ClientHttpRequestFactory} that buffers all outgoing and incoming streams in memory.
* Wrapper for a {@link ClientHttpRequestFactory} that buffers
* all outgoing and incoming streams in memory.
*
* <p>Using this wrapper allows for multiple reads of the {@linkplain ClientHttpResponse#getBody() response body}.
* <p>Using this wrapper allows for multiple reads of the
* @linkplain ClientHttpResponse#getBody() response body}.
*
* @author Arjen Poutsma
* @since 3.1
*/
public
class
BufferingClientHttpRequestFactory
extends
AbstractClientHttpRequestFactoryWrapper
{
/**
* Create a buffering wrapper for the given {@link ClientHttpRequestFactory}.
* @param requestFactory the target request factory to wrap
*/
public
BufferingClientHttpRequestFactory
(
ClientHttpRequestFactory
requestFactory
)
{
super
(
requestFactory
);
}
@Override
protected
ClientHttpRequest
createRequest
(
URI
uri
,
HttpMethod
httpMethod
,
ClientHttpRequestFactory
requestFactory
)
throws
IOException
{
ClientHttpRequest
request
=
requestFactory
.
createRequest
(
uri
,
httpMethod
);
if
(
shouldBuffer
(
uri
,
httpMethod
))
{
return
new
BufferingClientHttpRequestWrapper
(
request
);
...
...
@@ -48,11 +56,10 @@ public class BufferingClientHttpRequestFactory extends AbstractClientHttpRequest
}
/**
* Indicates whether the request/response exchange for the given URI and method should be buffered in memory.
*
* <p>Default implementation returns {@code true} for all URIs and methods. Subclasses can override this method to
* change this behavior.
*
* Indicates whether the request/response exchange for the given URI and method
* should be buffered in memory.
* <p>The default implementation returns {@code true} for all URIs and methods.
* Subclasses can override this method to change this behavior.
* @param uri the URI
* @param httpMethod the method
* @return {@code true} if the exchange should be buffered; {@code false} otherwise
...
...
@@ -60,4 +67,5 @@ public class BufferingClientHttpRequestFactory extends AbstractClientHttpRequest
protected
boolean
shouldBuffer
(
URI
uri
,
HttpMethod
httpMethod
)
{
return
true
;
}
}
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java
浏览文件 @
62565860
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -21,7 +21,6 @@ import java.net.URI;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StreamUtils
;
/**
...
...
@@ -36,7 +35,6 @@ final class BufferingClientHttpRequestWrapper extends AbstractBufferingClientHtt
BufferingClientHttpRequestWrapper
(
ClientHttpRequest
request
)
{
Assert
.
notNull
(
request
,
"'request' must not be null"
);
this
.
request
=
request
;
}
...
...
spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java
浏览文件 @
62565860
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -25,8 +25,8 @@ import org.springframework.http.HttpStatus;
import
org.springframework.util.StreamUtils
;
/**
* Simple implementation of {@link ClientHttpResponse} that reads the response's body
into memory,
* thus allowing for multiple invocations of {@link #getBody()}.
* Simple implementation of {@link ClientHttpResponse} that reads the response's body
*
into memory,
thus allowing for multiple invocations of {@link #getBody()}.
*
* @author Arjen Poutsma
* @since 3.1
...
...
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java
浏览文件 @
62565860
...
...
@@ -40,8 +40,8 @@ import org.springframework.core.annotation.AliasFor;
* details see the note on the new support classes added in Spring MVC 3.1
* further below.
*
* <p>Handler methods which are annotated with this annotation are allowed
*
to have very flexible signatures. They may have argument
s of the following
* <p>Handler methods which are annotated with this annotation are allowed
to
*
have very flexible signatures. They may have parameter
s of the following
* types, in arbitrary order (except for validation results, which need to
* follow right after the corresponding command object, if desired):
* <ul>
...
...
@@ -163,7 +163,7 @@ import org.springframework.core.annotation.AliasFor;
* context path, and the literal part of the servlet mapping.
* </ul>
*
* <p><strong>Note:</strong> J
DK 1.
8's {@code java.util.Optional} is supported
* <p><strong>Note:</strong> J
ava
8's {@code java.util.Optional} is supported
* as a method parameter type with annotations that provide a {@code required}
* attribute (e.g. {@code @RequestParam}, {@code @RequestHeader}, etc.). The use
* of {@code java.util.Optional} in those cases is equivalent to having
...
...
@@ -174,8 +174,8 @@ import org.springframework.core.annotation.AliasFor;
* <li>A {@code ModelAndView} object (Servlet MVC or Portlet MVC),
* with the model implicitly enriched with command objects and the results
* of {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods.
* <li>A {@link org.springframework.ui.Model Model} object, with the view name
*
implicitly
determined through a {@link org.springframework.web.servlet.RequestToViewNameTranslator}
* <li>A {@link org.springframework.ui.Model Model} object, with the view name
implicitly
* determined through a {@link org.springframework.web.servlet.RequestToViewNameTranslator}
* and the model implicitly enriched with command objects and the results
* of {@link ModelAttribute @ModelAttribute} annotated reference data accessor methods.
* <li>A {@link java.util.Map} object for exposing a model,
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java
浏览文件 @
62565860
...
...
@@ -143,10 +143,11 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
}
/**
* Set whether to serialize models containing a single attribute as a map or whether to
* extract the single value from the model and serialize it directly.
* <p>The effect of setting this flag is similar to using {@code MappingJackson2HttpMessageConverter}
* with an {@code @ResponseBody} request-handling method.
* Set whether to serialize models containing a single attribute as a map or
* whether to extract the single value from the model and serialize it directly.
* <p>The effect of setting this flag is similar to using
* {@code MappingJackson2HttpMessageConverter} with an {@code @ResponseBody}
* request-handling method.
* <p>Default is {@code false}.
*/
public
void
setExtractValueFromSingleKeyModel
(
boolean
extractValueFromSingleKeyModel
)
{
...
...
@@ -181,7 +182,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
* Filter out undesired attributes from the given model.
* The return value can be either another {@link Map} or a single value object.
* <p>The default implementation removes {@link BindingResult} instances and entries
* not included in the {@link #set
RenderedAttribute
s renderedAttributes} property.
* not included in the {@link #set
ModelKey
s renderedAttributes} property.
* @param model the model, as passed on to {@link #renderMergedOutputModel}
* @return the value to be rendered
*/
...
...
@@ -221,9 +222,10 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
if
(
this
.
jsonPrefix
!=
null
)
{
generator
.
writeRaw
(
this
.
jsonPrefix
);
}
String
jsonpFunction
=
null
;
if
(
object
instanceof
MappingJacksonValue
)
{
jsonpFunction
=
((
MappingJacksonValue
)
object
).
getJsonpFunction
();
jsonpFunction
=
((
MappingJacksonValue
)
object
).
getJsonpFunction
();
}
if
(
jsonpFunction
!=
null
)
{
generator
.
writeRaw
(
jsonpFunction
+
"("
);
...
...
@@ -234,7 +236,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
protected
void
writeSuffix
(
JsonGenerator
generator
,
Object
object
)
throws
IOException
{
String
jsonpFunction
=
null
;
if
(
object
instanceof
MappingJacksonValue
)
{
jsonpFunction
=
((
MappingJacksonValue
)
object
).
getJsonpFunction
();
jsonpFunction
=
((
MappingJacksonValue
)
object
).
getJsonpFunction
();
}
if
(
jsonpFunction
!=
null
)
{
generator
.
writeRaw
(
");"
);
...
...
src/asciidoc/web-mvc.adoc
浏览文件 @
62565860
...
...
@@ -635,8 +635,8 @@ controller. When this is the case, for controllers specifically, we recommend
using class-based proxying. This is typically the default choice with controllers.
However if a controller must implement an interface that is not a Spring Context
callback (e.g. `InitializingBean`, `*Aware`, etc), you may need to explicitly
configure class-based proxying. For example with `
<tx:annotation-driven
/>
`,
change to `
<tx:annotation-driven
proxy-target-class=
"true"
/>
`.
configure class-based proxying. For example with `
<tx:annotation-driven/>
`,
change to `
<tx:annotation-driven
proxy-target-class=
"true"
/>
`.
[[mvc-ann-requestmapping-31-vs-30]]
==== New Support Classes for @RequestMapping methods in Spring MVC 3.1
...
...
@@ -1368,8 +1368,8 @@ the MVC namespace or the MVC Java config see <<mvc-config-enable>> instead.
<bean
id=
"marshallingHttpMessageConverter"
class=
"org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
>
<property
name=
"marshaller"
ref=
"castorMarshaller"
/>
<property
name=
"unmarshaller"
ref=
"castorMarshaller"
/>
<property
name=
"marshaller"
ref=
"castorMarshaller"
/>
<property
name=
"unmarshaller"
ref=
"castorMarshaller"
/>
</bean>
<bean
id=
"castorMarshaller"
class=
"org.springframework.oxm.castor.CastorMarshaller"
/>
...
...
@@ -1897,9 +1897,9 @@ PropertyEditors required by several of the PetClinic controllers.
[subs="verbatim,quotes"]
----
<bean
class=
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"
>
<property
name=
"cacheSeconds"
value=
"0"
/>
<property
name=
"cacheSeconds"
value=
"0"
/>
<property
name=
"webBindingInitializer"
>
<bean
class=
"org.springframework.samples.petclinic.web.ClinicBindingInitializer"
/>
<bean
class=
"org.springframework.samples.petclinic.web.ClinicBindingInitializer"
/>
</property>
</bean>
----
...
...
@@ -4512,7 +4512,7 @@ context defined):
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"
>
<mvc:annotation-driven
/>
<mvc:annotation-driven/>
</beans>
----
...
...
@@ -4602,7 +4602,7 @@ and override the methods you need:
}
----
To customize the default configuration of `
<mvc:annotation-driven
/>
` check what
To customize the default configuration of `
<mvc:annotation-driven/>
` check what
attributes and sub-elements it supports. You can view the
http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use the code
completion feature of your IDE to discover what attributes and sub-elements are
...
...
@@ -4799,15 +4799,15 @@ And in XML use the `<mvc:interceptors>` element:
[subs="verbatim"]
----
<mvc:interceptors>
<bean
class=
"org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
/>
<bean
class=
"org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
/>
<mvc:interceptor>
<mvc:mapping
path=
"/**"
/>
<mvc:exclude-mapping
path=
"/admin/**"
/>
<bean
class=
"org.springframework.web.servlet.theme.ThemeChangeInterceptor"
/>
<bean
class=
"org.springframework.web.servlet.theme.ThemeChangeInterceptor"
/>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping
path=
"/secure/*"
/>
<bean
class=
"org.example.SecurityInterceptor"
/>
<bean
class=
"org.example.SecurityInterceptor"
/>
</mvc:interceptor>
</mvc:interceptors>
----
...
...
@@ -4858,7 +4858,7 @@ that in turn can be created with a `ContentNegotiationManagerFactoryBean`:
[source,xml,indent=0]
[subs="verbatim,quotes"]
----
<mvc:annotation-driven
content-negotiation-manager=
"contentNegotiationManager"
/>
<mvc:annotation-driven
content-negotiation-manager=
"contentNegotiationManager"
/>
<bean
id=
"contentNegotiationManager"
class=
"org.springframework.web.accept.ContentNegotiationManagerFactoryBean"
>
<property
name=
"favorPathExtension"
value=
"false"
/>
...
...
@@ -4954,10 +4954,10 @@ And the same in XML:
<mvc:view-resolvers>
<mvc:content-negotiation>
<mvc:default-views>
<bean
class=
"org.springframework.web.servlet.view.json.MappingJackson2JsonView"
/>
<bean
class=
"org.springframework.web.servlet.view.json.MappingJackson2JsonView"
/>
</mvc:default-views>
</mvc:content-negotiation>
<mvc:jsp
/>
<mvc:jsp/>
</mvc:view-resolvers>
----
...
...
@@ -4973,14 +4973,14 @@ The MVC namespace provides dedicated elements. For example with FreeMarker:
<mvc:view-resolvers>
<mvc:content-negotiation>
<mvc:default-views>
<bean
class=
"org.springframework.web.servlet.view.json.MappingJackson2JsonView"
/>
<bean
class=
"org.springframework.web.servlet.view.json.MappingJackson2JsonView"
/>
</mvc:default-views>
</mvc:content-negotiation>
<mvc:freemarker
cache=
"false"
/>
<mvc:freemarker
cache=
"false"
/>
</mvc:view-resolvers>
<mvc:freemarker-configurer>
<mvc:template-loader-path
location=
"/freemarker"
/>
<mvc:template-loader-path
location=
"/freemarker"
/>
</mvc:freemarker-configurer>
----
...
...
@@ -5158,7 +5158,7 @@ XML example:
----
<mvc:resources
mapping=
"/resources/**"
location=
"/public-resources/"
>
<mvc:resource-chain>
<mvc:resource-cache
/>
<mvc:resource-cache/>
<mvc:resolvers>
<mvc:version-resolver>
<mvc:content-version-strategy
patterns=
"/**"
/>
...
...
@@ -5306,11 +5306,11 @@ And the same in XML, use the `<mvc:path-matching>` element:
trailing-slash="false"
registered-suffixes-only="true"
path-helper="pathHelper"
path-matcher="pathMatcher"
/>
path-matcher="pathMatcher"/>
</mvc:annotation-driven>
<bean id="pathHelper" class="org.example.app.MyPathHelper"
/>
<bean id="pathMatcher" class="org.example.app.MyPathMatcher"
/>
<bean id="pathHelper" class="org.example.app.MyPathHelper"/>
<bean id="pathMatcher" class="org.example.app.MyPathMatcher"/>
----
...
...
@@ -5373,10 +5373,10 @@ It is also possible to do the same in XML:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper" ref="objectMapper"
/>
<property name="objectMapper" ref="objectMapper"/>
</bean>
<bean class="org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter">
<property name="objectMapper" ref="xmlMapper"
/>
<property name="objectMapper" ref="xmlMapper"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
...
...
@@ -5384,9 +5384,9 @@ It is also possible to do the same in XML:
<bean id="objectMapper" class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
p:indentOutput="true"
p:simpleDateFormat="yyyy-MM-dd"
p:modulesToInstall="com.fasterxml.jackson.module.paramnames.ParameterNamesModule"
/>
p:modulesToInstall="com.fasterxml.jackson.module.paramnames.ParameterNamesModule"/>
<bean id="xmlMapper" parent="objectMapper" p:createXmlMapper="true"
/>
<bean id="xmlMapper" parent="objectMapper" p:createXmlMapper="true"/>
----
...
...
@@ -5470,6 +5470,6 @@ by type and then modifying its properties as necessary. For example:
}
----
Note that `
MyPostProcessor
` needs to be included in an `
<
component
scan
/>
` in order for
Note that `
MyPostProcessor
` needs to be included in an `
<
component
scan
/>
` in order for
it to be detected or if you prefer you can declare it explicitly with an XML bean
declaration.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录