|
|
|
@ -12,36 +12,64 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
|
|
import com.tamguo.web.interceptor.MemberInterceptor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WebConfig 类,实现 WebMvcConfigurer 接口,用于配置 Web 相关的设置
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
@Value("${file.storage.path}")
|
|
|
|
|
private String fileStoragePath;
|
|
|
|
|
@Value("${cookie.domian.name}")
|
|
|
|
|
private String cookieDomianName;
|
|
|
|
|
/**
|
|
|
|
|
* 从配置文件中获取文件存储路径的值
|
|
|
|
|
*/
|
|
|
|
|
@Value("${file.storage.path}")
|
|
|
|
|
private String fileStoragePath;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberInterceptor memberInterceptor;
|
|
|
|
|
/**
|
|
|
|
|
* 从配置文件中获取 Cookie 域名的值
|
|
|
|
|
*/
|
|
|
|
|
@Value("${cookie.domian.name}")
|
|
|
|
|
private String cookieDomianName;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自动注入 MemberInterceptor 实例
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberInterceptor memberInterceptor;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
registry.addInterceptor(memberInterceptor).addPathPatterns("/**").excludePathPatterns("/login.html","/register.html","/password/**","/captcha.jpg" , "/submitLogin.html" , "/miniLogin.html","/static/**","/sendFindPasswordSms","/subRegister","/checkMobile.html","/checkUsername.html");
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 重写 addInterceptors 方法,添加拦截器
|
|
|
|
|
* @param registry 拦截器注册器
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
// 添加拦截器,并设置拦截路径和排除路径
|
|
|
|
|
registry.addInterceptor(memberInterceptor).addPathPatterns("/**").excludePathPatterns("/login.html", "/register.html", "/password/**", "/captcha.jpg", "/submitLogin.html", "/miniLogin.html", "/static/**", "/sendFindPasswordSms", "/subRegister", "/checkMobile.html", "/checkUsername.html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重写 addResourceHandlers 方法,添加资源处理器
|
|
|
|
|
* @param registry 资源处理器注册器
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
|
registry.addResourceHandler("/files/**").addResourceLocations("file:"+fileStoragePath);
|
|
|
|
|
// 添加资源处理器,处理/files/** 路径的资源,并设置资源位置为文件系统中的指定路径
|
|
|
|
|
registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileStoragePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建默认的 CookieSerializer 实例的方法
|
|
|
|
|
* @return 默认的 CookieSerializer 实例
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public CookieSerializer defaultCookieSerializer(){
|
|
|
|
|
public CookieSerializer defaultCookieSerializer() {
|
|
|
|
|
// 创建默认的 CookieSerializer 实例
|
|
|
|
|
DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
|
|
|
|
|
// 设置 Cookie 名称
|
|
|
|
|
defaultCookieSerializer.setCookieName("sessionId");
|
|
|
|
|
// 设置 Cookie 域名
|
|
|
|
|
defaultCookieSerializer.setDomainName(cookieDomianName);
|
|
|
|
|
// 设置 Cookie 路径
|
|
|
|
|
defaultCookieSerializer.setCookiePath("/");
|
|
|
|
|
return defaultCookieSerializer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|