package com.wms.controller;
import cn.hutool.extra.spring.SpringUtil;
import com.wms.exeception.MyException;
import com.wms.utils.getUserConfig;
import com.wms.vo.ResultCode;
import com.wms.vo.ResultVo;
import com.wms.vo.userVo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//在执行目标之前 判断用户是否登录,并封装
@Component
public class LoginInterceptor implements HandlerInterceptor {
StringRedisTemplate stringRedisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
//创建一个静态的threadLocal
public static ThreadLocal
package com.wms.controller;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class Interceptor implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("
@Component
public class CorsConfig {
@Bean
CorsFilter corsFilter(){
CorsConfiguration config = new CorsConfiguration();
// Possibly...
// config.applyPermitDefaultValues()
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
controller还需要加个跨域注解
@CrossOrigin



