diff --git a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/cors/CorsAutoConfiguration.java b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/cors/CorsAutoConfiguration.java index 6d5b015d..639e8df2 100644 --- a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/cors/CorsAutoConfiguration.java +++ b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/cors/CorsAutoConfiguration.java @@ -43,6 +43,7 @@ import top.continew.starter.core.constant.StringConstants; @ConditionalOnProperty(prefix = PropertiesConstants.WEB_CORS, name = PropertiesConstants.ENABLED, havingValue = "true") @EnableConfigurationProperties(CorsProperties.class) public class CorsAutoConfiguration { + private static final Logger log = LoggerFactory.getLogger(CorsAutoConfiguration.class); /** diff --git a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/WebMvcAutoConfiguration.java b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/WebMvcAutoConfiguration.java index ad1e434f..c332bc92 100644 --- a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/WebMvcAutoConfiguration.java +++ b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/WebMvcAutoConfiguration.java @@ -26,6 +26,11 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import top.continew.starter.web.autoconfigure.mvc.converter.BaseEnumConverterFactory; +import top.continew.starter.web.autoconfigure.mvc.converter.time.DateConverter; +import top.continew.starter.web.autoconfigure.mvc.converter.time.LocalDateConverter; +import top.continew.starter.web.autoconfigure.mvc.converter.time.LocalDateTimeConverter; +import top.continew.starter.web.autoconfigure.mvc.converter.time.LocalTimeConverter; import java.util.List; import java.util.Objects; @@ -70,6 +75,10 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { registry.addConverterFactory(new BaseEnumConverterFactory()); + registry.addConverter(new DateConverter()); + registry.addConverter(new LocalDateTimeConverter()); + registry.addConverter(new LocalDateConverter()); + registry.addConverter(new LocalTimeConverter()); } @PostConstruct diff --git a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverter.java b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverter.java similarity index 95% rename from continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverter.java rename to continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverter.java index 7e2d3aea..5b99a594 100644 --- a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverter.java +++ b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.web.autoconfigure.mvc; +package top.continew.starter.web.autoconfigure.mvc.converter; import org.springframework.core.convert.converter.Converter; import top.continew.starter.core.enums.BaseEnum; diff --git a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverterFactory.java b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverterFactory.java similarity index 95% rename from continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverterFactory.java rename to continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverterFactory.java index 20a64092..bad2e878 100644 --- a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/BaseEnumConverterFactory.java +++ b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/BaseEnumConverterFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.web.autoconfigure.mvc; +package top.continew.starter.web.autoconfigure.mvc.converter; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; diff --git a/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/time/DateConverter.java b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/time/DateConverter.java new file mode 100644 index 00000000..c33b6e5d --- /dev/null +++ b/continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/mvc/converter/time/DateConverter.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.web.autoconfigure.mvc.converter.time;
+
+import cn.hutool.core.date.DateUtil;
+import org.springframework.core.convert.converter.Converter;
+
+import java.util.Date;
+
+/**
+ * Date 参数转换器
+ *
+ * @author Charles7c
+ * @since 2.10.0
+ */
+public class DateConverter implements Converter
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.web.autoconfigure.mvc.converter.time;
+
+import cn.hutool.core.date.DateUtil;
+import org.springframework.core.convert.converter.Converter;
+
+import java.time.LocalDate;
+
+/**
+ * LocalDate 参数转换器
+ *
+ * @author Charles7c
+ * @since 2.10.0
+ */
+public class LocalDateConverter implements Converter
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.web.autoconfigure.mvc.converter.time;
+
+import cn.hutool.core.date.DateUtil;
+import org.springframework.core.convert.converter.Converter;
+
+import java.time.LocalDateTime;
+
+/**
+ * LocalDateTime 参数转换器
+ *
+ * @author Charles7c
+ * @since 2.10.0
+ */
+public class LocalDateTimeConverter implements Converter
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.web.autoconfigure.mvc.converter.time;
+
+import cn.hutool.core.date.DateUtil;
+import org.springframework.core.convert.converter.Converter;
+
+import java.time.LocalTime;
+
+/**
+ * LocalTime 参数转换器
+ *
+ * @author Charles7c
+ * @since 2.10.0
+ */
+public class LocalTimeConverter implements Converter