CustomInterceptorConfig.java 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. package com.pub.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
  5. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  6. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  7. import com.fasterxml.jackson.databind.DeserializationFeature;
  8. import com.fasterxml.jackson.databind.ObjectMapper;
  9. import com.pub.interceptor.CustomInterceptor;
  10. @Configuration
  11. public class CustomInterceptorConfig implements WebMvcConfigurer {
  12. @Override
  13. public void addInterceptors(InterceptorRegistry registry) {
  14. registry.addInterceptor(new CustomInterceptor()).addPathPatterns("/**").excludePathPatterns("/s/**",
  15. "/framework-ui/**","/ws/**", "/error/**", "/index/login", "/index/initData","/fileUpload/upload");
  16. }
  17. @Bean
  18. public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
  19. MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
  20. ObjectMapper objectMapper = new ObjectMapper();
  21. // 添加此配置
  22. objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  23. converter.setObjectMapper(objectMapper);
  24. return converter;
  25. }
  26. }