项目目录结构:

image.png

添加"/asserts/**""/webjars/**"放行静态资源即可:

package com.example.springbootcrud.config;

import com.example.springbootcrud.component.LoginHandlerInterceptor;
import com.example.springbootcrud.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
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;

import java.util.Arrays;

//使用WebMvcConfigurer可以来扩展SpringMvc的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

             @Override
             public void addInterceptors(InterceptorRegistry registry) {
                 registry.addInterceptor(new LoginHandlerInterceptor())
                  .addPathPatterns("/**").excludePathPatterns(Arrays.asList(
                          "/","/login.html","/user/login","/asserts/**",
                         "/webjars/**"));
             };
         };
         return adapter;
    }
}


WinRT
21 声望4 粉丝

临渊羡鱼,不如退而结网