Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
0bc01fcd
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,发现更多精彩内容 >>
提交
0bc01fcd
编写于
3月 30, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
7a8d41e5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
35 addition
and
37 deletion
+35
-37
spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java
...springframework/jdbc/core/SingleColumnRowMapperTests.java
+9
-5
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java
...g/springframework/web/filter/ShallowEtagHeaderFilter.java
+7
-13
src/docs/asciidoc/core/core-validation.adoc
src/docs/asciidoc/core/core-validation.adoc
+5
-5
src/docs/asciidoc/web/webflux.adoc
src/docs/asciidoc/web/webflux.adoc
+2
-2
src/docs/asciidoc/web/webmvc.adoc
src/docs/asciidoc/web/webmvc.adoc
+12
-12
未找到文件。
spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java
浏览文件 @
0bc01fcd
...
...
@@ -24,11 +24,12 @@ import java.sql.Timestamp;
import
java.time.LocalDateTime
;
import
org.junit.Test
;
import
org.springframework.core.convert.support.DefaultConversionService
;
import
org.springframework.dao.TypeMismatchDataAccessException
;
import
static
org
.
mockito
.
BDDMockito
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
BDDMockito
.*;
/**
* Tests for {@link SingleColumnRowMapper}.
...
...
@@ -38,7 +39,7 @@ import static org.junit.Assert.*;
*/
public
class
SingleColumnRowMapperTests
{
@Test
// SPR-16483
@Test
// SPR-16483
public
void
useDefaultConversionService
()
throws
SQLException
{
Timestamp
timestamp
=
new
Timestamp
(
0
);
...
...
@@ -57,7 +58,7 @@ public class SingleColumnRowMapperTests {
assertEquals
(
timestamp
.
toLocalDateTime
(),
actualLocalDateTime
);
}
@Test
// SPR-16483
@Test
// SPR-16483
public
void
useCustomConversionService
()
throws
SQLException
{
Timestamp
timestamp
=
new
Timestamp
(
0
);
...
...
@@ -81,7 +82,7 @@ public class SingleColumnRowMapperTests {
assertEquals
(
timestamp
.
toLocalDateTime
(),
actualMyLocalDateTime
.
value
);
}
@Test
(
expected
=
TypeMismatchDataAccessException
.
class
)
// SPR-16483
@Test
(
expected
=
TypeMismatchDataAccessException
.
class
)
// SPR-16483
public
void
doesNotUseConversionService
()
throws
SQLException
{
SingleColumnRowMapper
<
LocalDateTime
>
rowMapper
=
SingleColumnRowMapper
.
newInstance
(
LocalDateTime
.
class
,
null
);
...
...
@@ -97,9 +98,12 @@ public class SingleColumnRowMapperTests {
rowMapper
.
mapRow
(
resultSet
,
1
);
}
private
static
class
MyLocalDateTime
{
private
final
LocalDateTime
value
;
private
MyLocalDateTime
(
LocalDateTime
value
)
{
public
MyLocalDateTime
(
LocalDateTime
value
)
{
this
.
value
=
value
;
}
}
...
...
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java
浏览文件 @
0bc01fcd
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -126,10 +126,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
String
responseETag
=
generateETagHeaderValue
(
responseWrapper
.
getContentInputStream
(),
this
.
writeWeakETag
);
rawResponse
.
setHeader
(
HEADER_ETAG
,
responseETag
);
String
requestETag
=
request
.
getHeader
(
HEADER_IF_NONE_MATCH
);
if
(
requestETag
!=
null
&&
(
responseETag
.
equals
(
requestETag
)
||
responseETag
.
replaceFirst
(
"^W/"
,
""
).
equals
(
requestETag
.
replaceFirst
(
"^W/"
,
""
))
||
"*"
.
equals
(
requestETag
)))
{
if
(
requestETag
!=
null
&&
(
"*"
.
equals
(
requestETag
)
||
responseETag
.
equals
(
requestETag
)
||
responseETag
.
replaceFirst
(
"^W/"
,
""
).
equals
(
requestETag
.
replaceFirst
(
"^W/"
,
""
))))
{
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"ETag ["
+
responseETag
+
"] equal to If-None-Match, sending 304"
);
}
...
...
@@ -163,19 +161,15 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
* @param response the HTTP response
* @param responseStatusCode the HTTP response status code
* @param inputStream the response body
* @return {@code true} if eligible for ETag generation
;
{@code false} otherwise
* @return {@code true} if eligible for ETag generation
,
{@code false} otherwise
*/
protected
boolean
isEligibleForEtag
(
HttpServletRequest
request
,
HttpServletResponse
response
,
int
responseStatusCode
,
InputStream
inputStream
)
{
String
method
=
request
.
getMethod
();
if
(
responseStatusCode
>=
200
&&
responseStatusCode
<
300
&&
HttpMethod
.
GET
.
matches
(
method
))
{
if
(
responseStatusCode
>=
200
&&
responseStatusCode
<
300
&&
HttpMethod
.
GET
.
matches
(
method
))
{
String
cacheControl
=
response
.
getHeader
(
HEADER_CACHE_CONTROL
);
if
(
cacheControl
==
null
||
!
cacheControl
.
contains
(
DIRECTIVE_NO_STORE
))
{
return
true
;
}
return
(
cacheControl
==
null
||
!
cacheControl
.
contains
(
DIRECTIVE_NO_STORE
));
}
return
false
;
}
...
...
@@ -189,7 +183,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
* @see org.springframework.util.DigestUtils
*/
protected
String
generateETagHeaderValue
(
InputStream
inputStream
,
boolean
isWeak
)
throws
IOException
{
// length of W/ +
0 + "
+ 32bits md5 hash + "
// length of W/ +
" + 0
+ 32bits md5 hash + "
StringBuilder
builder
=
new
StringBuilder
(
37
);
if
(
isWeak
)
{
builder
.
append
(
"W/"
);
...
...
src/docs/asciidoc/core/core-validation.adoc
浏览文件 @
0bc01fcd
...
...
@@ -1106,7 +1106,7 @@ The `number` package provides a `NumberFormatter`, `CurrencyFormatter`, and
`PercentFormatter` to format `java.lang.Number` objects using a `java.text.NumberFormat`.
The `datetime` package provides a `DateFormatter` to format `java.util.Date` objects with
a `java.text.DateFormat`. The `datetime.joda` package provides comprehensive datetime
formatting support based on the http://joda-time.sourceforge.net[Joda
Time library].
formatting support based on the http://joda-time.sourceforge.net[Joda
-
Time library].
Consider `DateFormatter` as an example `Formatter` implementation:
...
...
@@ -1240,7 +1240,7 @@ To trigger formatting, simply annotate fields with @NumberFormat:
A portable format annotation API exists in the `org.springframework.format.annotation`
package. Use @NumberFormat to format java.lang.Number fields. Use @DateTimeFormat to
format java.util.Date, java.util.Calendar, java.util.Long, or Joda
Time fields.
format java.util.Date, java.util.Calendar, java.util.Long, or Joda
-
Time fields.
The example below uses @DateTimeFormat to format a java.util.Date as a ISO Date
(yyyy-MM-dd):
...
...
@@ -1344,10 +1344,10 @@ You will need to ensure that Spring does not register default formatters, and in
you
should
register
all
formatters
manually
.
Use
the
`
org
.
springframework
.
format
.
datetime
.
joda
.
JodaTimeFormatterRegistrar
`
or
`
org
.
springframework
.
format
.
datetime
.
DateFormatterRegistrar
`
class
depending
on
whether
you
use
the
Joda
Time
library
.
you
use
the
Joda
-
Time
library
.
For
example
,
the
following
Java
configuration
will
register
a
global
' `yyyyMMdd`'
format
.
This
example
does
not
depend
on
the
Joda
Time
library
:
format
.
This
example
does
not
depend
on
the
Joda
-
Time
library
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
...
...
@@ -1412,7 +1412,7 @@ Time:
[NOTE]
====
Joda
Time provides separate distinct types to represent `date`, `time` and `date-time`
Joda
-
Time provides separate distinct types to represent `date`, `time` and `date-time`
values. The `dateFormatter`, `timeFormatter` and `dateTimeFormatter` properties of the
`JodaTimeFormatterRegistrar` should be used to configure the different formats for each
type. The `DateTimeFormatterFactoryBean` provides a convenient way to create formatters.
...
...
src/docs/asciidoc/web/webflux.adoc
浏览文件 @
0bc01fcd
...
...
@@ -2452,8 +2452,8 @@ In your Java config implement the `WebFluxConfigurer` interface:
[.
small
]#<<
web
.
adoc
#
mvc
-
config
-
conversion
,
Same
in
Spring
MVC
>>#
By
default
formatters
for
`
Number
`
and
`
Date
`
types
are
installed
,
including
support
for
the
`@
NumberFormat
`
and
`@
DateTimeFormat
`
annotations
.
Full
support
for
the
Joda
Time
formatting
library
is
also
installed
if
Joda
Time
is
present
on
the
classpath
.
the
`@
NumberFormat
`
and
`@
DateTimeFormat
`
annotations
.
Full
support
for
the
Joda
-
Time
formatting
library
is
also
installed
if
Joda
-
Time
is
present
on
the
classpath
.
To
register
custom
formatters
and
converters
:
...
...
src/docs/asciidoc/web/webmvc.adoc
浏览文件 @
0bc01fcd
...
...
@@ -277,10 +277,10 @@ The table below lists the special beans detected by the `DispatcherHandler`:
=== Web MVC Config
[.small]#
<
<
web-reactive.adoc#webflux-framework-config
,
Same
in
Spring
WebFlux
>
>#
Applications can declare the infrastructure beans listed in
<
<
mvc-special-bean-types
>
>
Applications can declare the infrastructure beans listed in
<
<
mvc-s
ervlet-s
pecial-bean-types
>
>
that are required to process requests. The `DispatcherServlet` checks the
`WebApplicationContext` for each special bean. If there are no matching bean types,
it
falls back on the default types listed in
`WebApplicationContext` for each special bean. If there are no matching bean types,
it
falls back on the default types listed in
https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[DispatcherServlet.properties].
In most cases the
<
<
mvc-config
>
> is the best starting point. It declares the required
...
...
@@ -3733,9 +3733,9 @@ applications along with a configuration API to customize it.
For more advanced customizations, not available in the configuration API, see
<
<
mvc-config-advanced-java
>
> and
<
<
mvc-config-advanced-xml
>
>.
You do not need to understand the underlying beans created by the MVC Java config and
the
MVC namespace but if you want to learn more, see
<
<
mvc-servlet-special-bean-types
>
> and
<
<
mvc-servlet-config
>
>.
You do not need to understand the underlying beans created by the MVC Java config and
the MVC namespace but if you want to learn more, see
<
<
mvc-servlet-special-bean-types
>
>
and
<
<
mvc-servlet-config
>
>.
[[mvc-config-enable]]
...
...
@@ -3796,10 +3796,10 @@ In Java config implement `WebMvcConfigurer` interface:
}
----
In XML check attributes and sub-elements of `
<mvc:annotation-driven/>
`. You can
view the
http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use the cod
e
completion feature of your IDE to discover what attributes and sub-elements are
available.
In XML check attributes and sub-elements of `
<mvc:annotation-driven/>
`. You can
view the http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or us
e
the code completion feature of your IDE to discover what attributes and
sub-elements are
available.
...
...
@@ -3808,8 +3808,8 @@ available.
[.small]#
<
<
web-reactive.adoc#webflux-config-conversion
,
Same
in
Spring
WebFlux
>
>#
By default formatters for `Number` and `Date` types are installed, including support for
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda
Time
formatting library is also installed if Joda
Time is present on the classpath.
the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda
-
Time
formatting library is also installed if Joda
-
Time is present on the classpath.
In Java config, register custom formatters and converters:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录