提交 0bc01fcd 编写于 作者: J Juergen Hoeller

Polishing

上级 7a8d41e5
......@@ -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;
}
}
......
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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/");
......
......@@ -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.
......
......@@ -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:
......
......@@ -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-servlet-special-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 code
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 use
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.
先完成此消息的编辑!
想要评论请 注册