MvcConfig.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.yihu.wlyy.config;
  2. import com.yihu.wlyy.interceptors.DoctorInterceptor;
  3. import com.yihu.wlyy.interceptors.GateWayInterceptor;
  4. import com.yihu.wlyy.interceptors.PatientInterceptor;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.context.annotation.Profile;
  10. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  11. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  12. /**
  13. * Created by chenweida on 2017/4/6.
  14. */
  15. @Configuration
  16. //@Profile({"test", "prod"})
  17. public class MvcConfig extends WebMvcConfigurerAdapter {
  18. private Logger logger = LoggerFactory.getLogger(MvcConfig.class);
  19. @Autowired
  20. private DoctorInterceptor doctorInterceptor;
  21. @Autowired
  22. private PatientInterceptor patientInterceptor;
  23. @Autowired
  24. private GateWayInterceptor gateWayInterceptor;
  25. @Override
  26. public void addInterceptors(InterceptorRegistry registry) {
  27. // 多个拦截器组成一个拦截器链
  28. // addPathPatterns 用于添加拦截规则
  29. // excludePathPatterns 用户排除拦截
  30. registry.addInterceptor(gateWayInterceptor).addPathPatterns("/wlyygc/**").excludePathPatterns("/wlyygc/doctor/**","/wlyygc/patient/**");
  31. registry.addInterceptor(doctorInterceptor).addPathPatterns("/doctor/**", "/statistics/province/**", "/statistics/**", "wlyygc/doctor/**");
  32. registry.addInterceptor(patientInterceptor).addPathPatterns("/patient/**","/wlyygc/patient/**");
  33. super.addInterceptors(registry);
  34. logger.info("init doctorInterceptor,patientInterceptor");
  35. }
  36. // /**
  37. // * 为null的数据不返回
  38. // * @param converters
  39. // */
  40. // @Override
  41. // public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
  42. // MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
  43. // ObjectMapper objectMapper=new ObjectMapper();
  44. // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  45. // mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
  46. // converters.add(mappingJackson2HttpMessageConverter);
  47. // }
  48. }