zoukankan      html  css  js  c++  java
  • springboot项目在所有的controller里加上统一前缀

    import com.oigit.imsapi.common.WebInterceptor;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    @Configuration
    public class WebConfig implements WebMvcConfigurer {
        /**
         * 请求路径添加统一前缀
         * @param configurer
         */
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.addPathPrefix("/imsApi", c -> c.isAnnotationPresent(Controller.class) || c.isAnnotationPresent(RestController.class));
        }
    
        @Bean
        public WebInterceptor getInstance(){
            return new WebInterceptor();
        }
        /**
         * 拦截器
         * @param registry
         */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(getInstance())
                    .addPathPatterns("/**")
                    .excludePathPatterns("/imsApi/login/**");
        }
        /**
         * 跨域支持
         * @param registry
         */
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowCredentials(true)
                    .allowedHeaders("*")
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .maxAge(3600);
        }
    }
  • 相关阅读:
    1、线性DP 198. 打家劫舍
    1、线性DP 354. 俄罗斯套娃信封问题
    127. 单词接龙
    1. 线性DP 887. 鸡蛋掉落 (DP+二分)
    200. 岛屿数量
    1. 线性DP 152. 乘积最大子数组
    1. 线性DP 53. 最大子序和.
    1. 线性DP 120. 三角形最小路径和
    如何在RHEL 8上安装Python 3
    在Ubuntu 20.04 LTS Focal Fossa上安装Drupal
  • 原文地址:https://www.cnblogs.com/i-tao/p/15590041.html
Copyright © 2011-2022 走看看