|
@@ -8,16 +8,26 @@
|
8
|
8
|
|
9
|
9
|
package com.api.config;
|
10
|
10
|
|
|
11
|
+import com.api.converter.CustomMessageConverter;
|
|
12
|
+import com.api.form.ChildConvertForm;
|
11
|
13
|
import com.common.interceptor.AuthorizationInterceptor;
|
12
|
14
|
import com.api.resolver.LoginUserHandlerMethodArgumentResolver;
|
13
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
16
|
import org.springframework.context.annotation.Configuration;
|
|
17
|
+import org.springframework.core.convert.converter.Converter;
|
|
18
|
+import org.springframework.format.FormatterRegistry;
|
|
19
|
+import org.springframework.http.MediaType;
|
|
20
|
+import org.springframework.http.converter.HttpMessageConverter;
|
|
21
|
+import org.springframework.web.accept.ParameterContentNegotiationStrategy;
|
15
|
22
|
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|
23
|
+import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
16
|
24
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
17
|
25
|
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
18
|
26
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
19
|
27
|
import org.springframework.web.util.UrlPathHelper;
|
20
|
28
|
|
|
29
|
+import java.util.Arrays;
|
|
30
|
+import java.util.HashMap;
|
21
|
31
|
import java.util.List;
|
22
|
32
|
|
23
|
33
|
/**
|
|
@@ -49,4 +59,37 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
49
|
59
|
urlPathHelper.setRemoveSemicolonContent(false);
|
50
|
60
|
configurer.setUrlPathHelper(urlPathHelper);
|
51
|
61
|
}
|
|
62
|
+
|
|
63
|
+ @Override
|
|
64
|
+ public void addFormatters(FormatterRegistry registry) {
|
|
65
|
+ registry.addConverter(new Converter<String, ChildConvertForm>() {
|
|
66
|
+ @Override
|
|
67
|
+ public ChildConvertForm convert(String s) {
|
|
68
|
+ if(!s.isEmpty()) {
|
|
69
|
+ String[] split = s.split(",");
|
|
70
|
+ ChildConvertForm childConvertForm = new ChildConvertForm();
|
|
71
|
+ childConvertForm.setChildName(split[0]);
|
|
72
|
+ childConvertForm.setChildAge(Integer.parseInt(split[1]));
|
|
73
|
+ return childConvertForm;
|
|
74
|
+ }
|
|
75
|
+ return null;
|
|
76
|
+ }
|
|
77
|
+ });
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Override
|
|
81
|
+ public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
82
|
+ converters.add(new CustomMessageConverter());
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Override
|
|
86
|
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
87
|
+ HashMap<String, MediaType> stringMediaTypeHashMap = new HashMap<>();
|
|
88
|
+ stringMediaTypeHashMap.put("json",MediaType.APPLICATION_JSON);
|
|
89
|
+ stringMediaTypeHashMap.put("xml",MediaType.APPLICATION_XML);
|
|
90
|
+ stringMediaTypeHashMap.put("zxy",MediaType.parseMediaType("application/x-zxy"));
|
|
91
|
+ ParameterContentNegotiationStrategy parameterContentNegotiationStrategy =
|
|
92
|
+ new ParameterContentNegotiationStrategy(stringMediaTypeHashMap);
|
|
93
|
+ configurer.strategies(Arrays.asList(parameterContentNegotiationStrategy));
|
|
94
|
+ }
|
52
|
95
|
}
|