|  | @@ -3,19 +3,25 @@ package com.ym.mec.student.config;
 | 
	
		
			
				|  |  |  import java.util.ArrayList;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  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.ym.mec.common.config.EnumConverterFactory;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.config.LocalFastJsonHttpMessageConverter;
 | 
	
		
			
				|  |  | +import com.ym.mec.student.interceptor.RequestInterceptor;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Configuration
 | 
	
		
			
				|  |  |  public class WebMvcConfig implements WebMvcConfigurer {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private RequestInterceptor requestInterceptor;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	/**
 | 
	
		
			
				|  |  |  	 * 枚举类的转换器 addConverterFactory
 | 
	
		
			
				|  |  |  	 */
 | 
	
	
		
			
				|  | @@ -23,14 +29,27 @@ public class WebMvcConfig implements WebMvcConfigurer {
 | 
	
		
			
				|  |  |  	public void addFormatters(FormatterRegistry registry) {
 | 
	
		
			
				|  |  |  		registry.addConverterFactory(new EnumConverterFactory());
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void addInterceptors(InterceptorRegistry registry) {
 | 
	
		
			
				|  |  | +		// addPathPatterns 用于添加拦截规则, 这里假设拦截 /url 后面的全部链接
 | 
	
		
			
				|  |  | +		List<String> includePathPatterns = new ArrayList<String>();
 | 
	
		
			
				|  |  | +		includePathPatterns.add("/**");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		// excludePathPatterns 用户排除拦截
 | 
	
		
			
				|  |  | +		List<String> excludePathPatterns = new ArrayList<String>();
 | 
	
		
			
				|  |  | +		excludePathPatterns.add("/login");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		registry.addInterceptor(requestInterceptor).addPathPatterns(includePathPatterns).excludePathPatterns(excludePathPatterns);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Bean
 | 
	
		
			
				|  |  | -    public HttpMessageConverters fastJsonHttpMessageConverters(){
 | 
	
		
			
				|  |  | +	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);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +		List<MediaType> fastMediaTypes = new ArrayList<MediaType>();
 | 
	
		
			
				|  |  | +		fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
 | 
	
		
			
				|  |  | +		converter.setSupportedMediaTypes(fastMediaTypes);
 | 
	
		
			
				|  |  | +		return new HttpMessageConverters(converter);
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 |