1. 程式人生 > >springboot 實現攔截器許可權過濾,以及用攔截器實現操作日誌功能(二)

springboot 實現攔截器許可權過濾,以及用攔截器實現操作日誌功能(二)

接上文

繼承WebMvcConfigurerAdapter 類,新增 上文寫的攔截類

具體程式碼如下:

package com.hcmony.web.interceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/** * <h3>許可權攔截</h3> * <p></p> * @author hcmony * @since V1.0.0, 2017/12/15 18:13 */ @Configuration public class InterceptorConfigurer extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { // 多個攔截器組成一個攔截器鏈 // addPathPatterns
用於新增攔截規則 registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/*/*"); // excludePathPatterns 使用者排除攔截 //registry.addInterceptor(new AuthInterceptor()).excludePathPatterns("/"); super.addInterceptors(registry); } }