1
- 創(chuàng)建interceptor類并實(shí)現(xiàn)org.springframework.web.servlet.HandlerInterceptor并實(shí)現(xiàn)其方法
- 在類上添加@Component注解

image.png
2
- 創(chuàng)建配置類并繼承org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
- 在該類上添加 @Configuration 注解
- 實(shí)現(xiàn)WebMvcConfigurerAdapter類的addInterceptors方法

image.png