|
@@ -0,0 +1,37 @@
|
|
1
|
+package com.config;
|
|
2
|
+
|
|
3
|
+import com.converter.DateConverter;
|
|
4
|
+import com.interceptor.MyInterceptor;
|
|
5
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+import org.springframework.context.annotation.Configuration;
|
|
7
|
+import org.springframework.core.convert.converter.Converter;
|
|
8
|
+import org.springframework.format.FormatterRegistry;
|
|
9
|
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
10
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
11
|
+
|
|
12
|
+import java.text.ParseException;
|
|
13
|
+import java.text.SimpleDateFormat;
|
|
14
|
+import java.util.Date;
|
|
15
|
+
|
|
16
|
+@Configuration
|
|
17
|
+public class WebMvcConfig implements WebMvcConfigurer {
|
|
18
|
+ @Override
|
|
19
|
+ public void addFormatters(FormatterRegistry registry) {
|
|
20
|
+ registry.addConverter(new Converter<String, Date>() {
|
|
21
|
+ public Date convert(String s) {
|
|
22
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
23
|
+ Date date = null;
|
|
24
|
+ try {
|
|
25
|
+ date = simpleDateFormat.parse(s);
|
|
26
|
+ } catch (ParseException e) {
|
|
27
|
+ e.printStackTrace();
|
|
28
|
+ }
|
|
29
|
+ return date;
|
|
30
|
+ }
|
|
31
|
+ });
|
|
32
|
+ }
|
|
33
|
+ @Override
|
|
34
|
+ public void addInterceptors(InterceptorRegistry registry) {
|
|
35
|
+// WebMvcConfigurer.super.addInterceptors(registry);
|
|
36
|
+ }
|
|
37
|
+}
|