wisdomisite-java/src/main/java/com/zhgd/xmgl/config/MyWebMvcConfigurerAdapter.java
2024-06-02 01:17:46 +08:00

58 lines
2.1 KiB
Java

package com.zhgd.xmgl.config;
import com.license.entity.dto.LicenseCheckInterceptor;
import com.zhgd.interceptor.LogInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @program: diseaseManage
* @description:
* @author: Mr.Peng
* @create: 2020-02-18 12:08
**/
@Configuration
class MyWebMvcConfigurerAdapter implements WebMvcConfigurer {
@Value("${basePath}")
private String path;
/*@Autowired
private Environment env ;*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//log.info("+++++++++++++++++++++++++++++++++++++++++++++++++++:"+env.getProperty("basePath"));
String staticMapping = "/image/**";
String localDirectory = "file:" + path;
registry.addResourceHandler(staticMapping).addResourceLocations(localDirectory);
//WebMvcConfigurer.super.addResourceHandlers(registry);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/document/").setViewName("forward:/document/index.html");
registry.addViewController("/").setViewName("forward:/index.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//super.addViewControllers(registry);
}
/**
* 添加拦截器
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**");
registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/xmgl/base/login");
registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/account/user/login");
}
}