Support date conversion format for java.time types

Prior to this change, the Spring MVC auto-configuration would add a new
formatter to convert `java.util.Date` to/from `String` using the
configured configuration property `spring.mvc.date-format`.

This commit adds a new `WebConversionService` class that registers
date formatters with a custom date format, or register the default ones
if no custom configuration is provided.
This avoids duplicating equivalent formatters in the registry.

With this change, date types from `java.util`, `org.joda.time` and
`java.time` are now all supported.

This commit also replicates this feature for WebFlux applications by
adding a new `spring.webflux.date-format` configuration property.

Closes gh-5523
Closes gh-11402
This commit is contained in:
Brian Clozel
2017-12-22 15:42:10 +01:00
parent ec26488ff1
commit 2fa0539e7f
7 changed files with 411 additions and 193 deletions

View File

@@ -465,7 +465,8 @@ content into your application. Rather, pick only the properties that you need.
spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.
spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.
# SPRING WEB FLUX ({sc-spring-boot-autoconfigure}/web/reactive/WebFluxProperties.{sc-ext}[WebFluxProperties])
# SPRING WEBFLUX ({sc-spring-boot-autoconfigure}/web/reactive/WebFluxProperties.{sc-ext}[WebFluxProperties])
spring.webflux.date-format= # Date format to use. For instance, `dd/MM/yyyy`.
spring.webflux.static-path-pattern=/** # Path pattern used for static resources.
# SPRING WEB SERVICES ({sc-spring-boot-autoconfigure}/webservices/WebServicesProperties.{sc-ext}[WebServicesProperties])