首页>代码>Spring Boot + MyBatis + AOP + LayUI实现权限管理系统>/lab/src/main/java/com/neusoft/demosb/config/MyMvcConfig.java
package com.neusoft.demosb.config;
import com.neusoft.demosb.component.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//已经过时,WebMvcConfigurer接口中有它的全部方法(WebMvcConfigurerAdapter适配器,相当于中间商)
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* @author wenchang
* @since 2020-06-04 10:01
*/
//使用WebMvcConfigurer来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
/* public void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
//浏览器发送 /test 请求来到 success
registry.addViewController("/test").setViewName("test");
registry.addViewController("/test.html").setViewName("test");
}*/
//多个请求同时生效(所以组件一起起作用)
@Bean//将组件注册在容器中
public WebMvcConfigurer webMvcConfigurer(){
WebMvcConfigurer adapter = new WebMvcConfigurer() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/test").setViewName("test");
registry.addViewController("/tests").setViewName("test");
registry.addViewController("/index.html").setViewName("index");
}
//注册拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
//super.addInterceptors(registry);
//静态资源; *.css , *.js
//SpringBoot已经做好了静态资源映射
//拦截所以/admin/路径下的请求,除了excludePathPatterns下面开放的请求:
registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/admin/**")
.excludePathPatterns("/admin","/admin/toLogin","/admin/login");
}
};
return adapter;
}
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
//
// }
}
最近下载更多
ttg2025 LV3
7月14日
李朝磊 LV18
2024年5月27日
interface LV22
2024年5月7日
微信网友_6906962132258816 LV7
2024年4月21日
HANCW LV9
2024年4月16日
ww0408 LV1
2023年12月28日
WBelong LV8
2023年12月26日
fff2003 LV9
2023年11月14日
1003480239 LV7
2023年5月29日
微信网友_6319582217965568 LV3
2023年2月18日

最近浏览