package org.linlinjava.jz.hm.config.mvc;


import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfigurerImpl implements WebMvcConfigurer {

	@Bean
	public WebInterceptor webInterceptor() {
		return new WebInterceptor();
	}

//	@Bean
//	public MyArgumentResolver myArgumentResolver() {
//		return new MyArgumentResolver();
//	}

	// 定义sourciId
//	@Override
//	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
//		// TODO Auto-generated method stub
//		resolvers.add(myArgumentResolver());
//	}

	// 拦截器
	public void addInterceptors(InterceptorRegistry registry) {
		// 增加一个拦截器
		registry.addInterceptor(webInterceptor()).addPathPatterns("/**")
		.excludePathPatterns("/swagger-resources/**","/webjars/**", "/v2/**", "/swagger-ui.html/**"
			,"/index.html","/pagers/**"	);
	}

	// 静态资源
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

	@Bean
	public FilterRegistrationBean httpServletRequestReplacedRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new BodyReaderRequestFilter());
		registration.addUrlPatterns("/*");
		registration.addInitParameter("paramName", "paramValue");
		registration.setName("BodyReaderRequestFilter");
		registration.setOrder(1);
		return registration;
	}
}