SpringMvcConfig.java 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. package com.lovecoding.mvc.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.ComponentScan;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.core.convert.converter.Converter;
  6. import org.springframework.format.FormatterRegistry;
  7. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  8. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  9. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  10. @Configuration
  11. @ComponentScan("com.lovecoding.mvc")
  12. @EnableWebMvc
  13. public class SpringMvcConfig implements WebMvcConfigurer {
  14. public void addFormatters(FormatterRegistry registry) {
  15. registry.addConverter(new DateConverter());
  16. }
  17. // public void addInterceptors(InterceptorRegistry registry) {
  18. //
  19. // //如此配置 全局可用 当前框架所有MVC请求都被 拦截器过滤了
  20. // //registry.addInterceptor( new MyInterceptor() );
  21. //
  22. // //拦截指定URL 请求, 并排除其他URL路径
  23. // registry.addInterceptor( new MyInterceptor() )
  24. // .addPathPatterns("/mybatis")
  25. // .excludePathPatterns("/login");
  26. //
  27. // }
  28. }