diff options
Diffstat (limited to 'src/main/java/com/mesasoft/cn/config/WebMvcConfig.java')
| -rw-r--r-- | src/main/java/com/mesasoft/cn/config/WebMvcConfig.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/com/mesasoft/cn/config/WebMvcConfig.java b/src/main/java/com/mesasoft/cn/config/WebMvcConfig.java new file mode 100644 index 0000000..51380b4 --- /dev/null +++ b/src/main/java/com/mesasoft/cn/config/WebMvcConfig.java @@ -0,0 +1,63 @@ +package com.mesasoft.cn.config; + +import com.alibaba.fastjson.JSONObject; +import com.mesasoft.cn.exception.GlobalExceptionHandler; +import com.mesasoft.cn.interceptor.WebInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.HandlerExceptionResolver; +import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +import java.util.List; + +/** + * @author pantao + * @since 2018/1/22 + */ +@Configuration +public class WebMvcConfig implements WebMvcConfigurer { + + @Override + public void configureViewResolvers(ViewResolverRegistry registry) { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/"); + viewResolver.setSuffix(".html"); + registry.viewResolver(viewResolver); + } + + @Override + public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) { + resolvers.add(globalExceptionHandler()); + } + + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + configurer.setUseSuffixPatternMatch(false); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(webInterceptor()); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/"); + } + + @Bean + public WebInterceptor webInterceptor() { + return new WebInterceptor(); + } + + @Bean + public GlobalExceptionHandler globalExceptionHandler() { + return new GlobalExceptionHandler(); + } + + @Bean + public JSONObject jsonObject() { + return new JSONObject(); + } +} |
