|
|
@@ -8,14 +8,10 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
-import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|
|
-import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
-import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -28,34 +24,10 @@ import java.util.List;
|
|
|
@ComponentScan
|
|
|
public class WebAppConfiguration extends WebMvcConfigurerAdapter {
|
|
|
|
|
|
- @Override
|
|
|
- public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
- // Spring boot默认资源路径在src/main/resources下,而非/src/main/webapp
|
|
|
- // 使用/src/main/webapp下资源均需在此添加
|
|
|
- registry.addResourceHandler("/static/**").addResourceLocations("/resources/");
|
|
|
- registry.addResourceHandler("/WEB-INF/**").addResourceLocations("/WEB-INF/");
|
|
|
- super.addResourceHandlers(registry);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void configureViewResolvers(ViewResolverRegistry registry) {
|
|
|
- InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/WEB-INF/views/", ".html");
|
|
|
- viewResolver.setContentType("text/html;charset=UTF-8");
|
|
|
- registry.viewResolver(viewResolver);
|
|
|
- super.configureViewResolvers(registry);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addViewControllers(ViewControllerRegistry registry) {
|
|
|
- registry.addViewController("/").setViewName("index");
|
|
|
- registry.addViewController("/index").setViewName("index");
|
|
|
- super.addViewControllers(registry);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
|
|
|
- fastJsonHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
|
|
|
+ fastJsonHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8));
|
|
|
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
|
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
|
|
|
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
|
|
|
@@ -63,7 +35,7 @@ public class WebAppConfiguration extends WebMvcConfigurerAdapter {
|
|
|
|
|
|
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(
|
|
|
Charset.forName("UTF-8"));
|
|
|
- stringHttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_HTML));
|
|
|
+ stringHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
|
|
|
converters.add(stringHttpMessageConverter);
|
|
|
super.configureMessageConverters(converters);
|
|
|
}
|