首页>代码>Spring Boot + MyBatis + AOP + LayUI实现权限管理系统>/lab/src/main/java/com/neusoft/demosb/config/MyMvcConfig.java
01 | package com.neusoft.demosb.config; |
02 |
03 |
04 | import com.neusoft.demosb.component.LoginHandlerInterceptor; |
05 | import org.springframework.context.annotation.Bean; |
06 | import org.springframework.context.annotation.Configuration; |
07 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
08 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; |
09 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
10 | //已经过时,WebMvcConfigurer接口中有它的全部方法(WebMvcConfigurerAdapter适配器,相当于中间商) |
11 | //import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
12 |
13 | /** |
14 | * @author wenchang |
15 | * @since 2020-06-04 10:01 |
16 | */ |
17 | //使用WebMvcConfigurer来扩展SpringMVC的功能 |
18 | @Configuration |
19 | public class MyMvcConfig implements WebMvcConfigurer { |
20 |
21 | /* public void addViewControllers(ViewControllerRegistry registry) { |
22 | // super.addViewControllers(registry); |
23 | //浏览器发送 /test 请求来到 success |
24 | registry.addViewController("/test").setViewName("test"); |
25 | registry.addViewController("/test.html").setViewName("test"); |
26 | }*/ |
27 |
28 | //多个请求同时生效(所以组件一起起作用) |
29 | @Bean //将组件注册在容器中 |
30 | public WebMvcConfigurer webMvcConfigurer(){ |
31 | WebMvcConfigurer adapter = new WebMvcConfigurer() { |
32 | @Override |
33 | public void addViewControllers(ViewControllerRegistry registry) { |
34 | registry.addViewController( "/test" ).setViewName( "test" ); |
35 | registry.addViewController( "/tests" ).setViewName( "test" ); |
36 | registry.addViewController( "/index.html" ).setViewName( "index" ); |
37 | } |
38 |
39 | //注册拦截器 |
40 | @Override |
41 | public void addInterceptors(InterceptorRegistry registry) { |
42 | //super.addInterceptors(registry); |
43 | //静态资源; *.css , *.js |
44 | //SpringBoot已经做好了静态资源映射 |
45 | //拦截所以/admin/路径下的请求,除了excludePathPatterns下面开放的请求: |
46 | registry.addInterceptor( new LoginHandlerInterceptor()).addPathPatterns( "/admin/**" ) |
47 | .excludePathPatterns( "/admin" , "/admin/toLogin" , "/admin/login" ); |
48 | } |
49 | }; |
50 | return adapter; |
51 | } |
52 |
53 | // @Override |
54 | // public void addInterceptors(InterceptorRegistry registry) { |
55 | // |
56 | // } |
57 | } |

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日