1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package com.yihu.wlyy.config;
- import com.yihu.wlyy.interceptors.DoctorInterceptor;
- import com.yihu.wlyy.interceptors.GateWayInterceptor;
- import com.yihu.wlyy.interceptors.PatientInterceptor;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.context.annotation.Profile;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
- /**
- * Created by chenweida on 2017/4/6.
- */
- @Configuration
- @Profile({"test", "prod"})
- public class MvcConfig extends WebMvcConfigurerAdapter {
- private Logger logger = LoggerFactory.getLogger(MvcConfig.class);
- @Autowired
- private DoctorInterceptor doctorInterceptor;
- @Autowired
- private PatientInterceptor patientInterceptor;
- @Autowired
- private GateWayInterceptor gateWayInterceptor;
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- // 多个拦截器组成一个拦截器链
- // addPathPatterns 用于添加拦截规则
- // excludePathPatterns 用户排除拦截
- registry.addInterceptor(gateWayInterceptor).addPathPatterns("/wlyygc/**").excludePathPatterns("/wlyygc/doctor/**","/wlyygc/patient/**");
- registry.addInterceptor(doctorInterceptor).addPathPatterns("/doctor/**", "/statistics/province/**", "/statistics/**", "wlyygc/doctor/**");
- registry.addInterceptor(patientInterceptor).addPathPatterns("/patient/**","/wlyygc/patient/**");
- super.addInterceptors(registry);
- logger.info("init doctorInterceptor,patientInterceptor");
- }
- // /**
- // * 为null的数据不返回
- // * @param converters
- // */
- // @Override
- // public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
- // MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
- // ObjectMapper objectMapper=new ObjectMapper();
- // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- // mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
- // converters.add(mappingJackson2HttpMessageConverter);
- // }
- }
|