拦截器代码
package com.centaline.employpay.interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {
@Bean
public HandlerInterceptor getPcInterceptor() {
return new PCLoginInterceptor();
}
@Bean
public HandlerInterceptor getMyInterceptor() {
return new WeChatLoginInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(getPcInterceptor()).addPathPatterns("/api/**").excludePathPatterns("/static/**");
registry.addInterceptor(getMyInterceptor()).addPathPatterns("/lan-jie/**").excludePathPatterns("/static/**").excludePathPatterns("/not-lan-jie");
super.addInterceptors(registry);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("/", "classpath:/");
}
}
页面上静态资源访问需要加上项目名
<link href="/employpay/static/css/style.css" rel="stylesheet">
<link href="/employpay/static/css/c-style.css" rel="stylesheet">
<link href="/employpay/static/css/style-responsive.css" rel="stylesheet">
<link href="/employpay/static/css/new_style.css" rel="stylesheet">
``
在本地运行时,在配置文件中加项目名,
发布时注解掉.
server.servlet.context-path=/employpay