1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package com.keao.edu.user.config;
- import java.util.ArrayList;
- import java.util.List;
- import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.format.FormatterRegistry;
- import org.springframework.http.MediaType;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
- import com.keao.edu.common.config.EnumConverterFactory;
- import com.keao.edu.common.config.LocalFastJsonHttpMessageConverter;
- import com.keao.edu.common.tenant.TenantInterceptor;
- import com.keao.edu.datasource.interceptor.DataSourceInterceptor;
- @Configuration
- public class WebMvcConfig implements WebMvcConfigurer {
- /**
- * 枚举类的转换器 addConverterFactory
- */
- @Override
- public void addFormatters(FormatterRegistry registry) {
- registry.addConverterFactory(new EnumConverterFactory());
- }
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(getDataSrouceInterceptor()).addPathPatterns("/**");
- registry.addInterceptor(getTenantInterceptor()).addPathPatterns("/**");
- }
- @Bean
- public DataSourceInterceptor getDataSrouceInterceptor() {
- return new DataSourceInterceptor();
- }
- @Bean
- public TenantInterceptor getTenantInterceptor() {
- return new TenantInterceptor();
- }
-
- @Bean
- public HttpMessageConverters fastJsonHttpMessageConverters(){
- LocalFastJsonHttpMessageConverter converter = new LocalFastJsonHttpMessageConverter();
- List<MediaType> fastMediaTypes = new ArrayList<MediaType>();
- fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
- converter.setSupportedMediaTypes(fastMediaTypes);
- return new HttpMessageConverters(converter);
- }
- }
|