首页>代码>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) { // // } }
最近下载更多
微信网友_6906962132258816 LV6
4月21日
HANCW LV8
4月16日
ww0408 LV1
2023年12月28日
WBelong LV7
2023年12月26日
fff2003 LV6
2023年11月14日
1003480239 LV7
2023年5月29日
微信网友_6319582217965568 LV3
2023年2月18日
LCL10086 LV3
2023年1月16日
Exposed LV9
2022年10月6日
testMysql LV2
2022年7月8日