当前位置:网站首页>Use of interceptors webmvcconfigurer
Use of interceptors webmvcconfigurer
2022-06-13 03:05:00 【good_ boys】
1 Introduce
WebMvcConfigurer The configuration class is actually Spring An internal configuration , use JavaBean Instead of the traditional xml The configuration file is customized for the framework , You can customize some Handler,Interceptor,ViewResolver,MessageConverter. be based on java-based The way of spring mvc To configure , You need to create a configuration class and implement WebMvcConfigurer Interface ;
stay Spring Boot 1.5 Versions are rewritten WebMvcConfigurerAdapter To add a custom interceptor , Message converter, etc .SpringBoot 2.0 after , This class is marked as @Deprecated( Abandoning ). The official recommendation is implemented directly WebMvcConfigurer Or direct inheritance WebMvcConfigurationSupport, The first way is to realize WebMvcConfigurer Interface ( recommend ), Mode 2 inheritance WebMvcConfigurationSupport class , See this article for specific implementation .https://blog.csdn.net/fmwind/article/details/82832758
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
@EnableWebMvc
public class InterceptorConfiguration implements WebMvcConfigurer {
@Resource
private SessionInterceptor sessionInterceptor;
@Resource
private WechatInterceptor wechatInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(sessionInterceptor)
.addPathPatterns("/**")
.order(Ordered.HIGHEST_PRECEDENCE);
registry.addInterceptor(wechatInterceptor)
.addPathPatterns("/testApp/**")
.order(Ordered.LOWEST_PRECEDENCE);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*/
@Component
public class WechatInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// todo Do something
ContextUtil.put(HeaderConstant.STORE_SHOP_USER,dto);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
}
}
边栏推荐
- Entity framework extends the actual combat, small project reconfiguration, no trouble
- 最近最少使用缓存(来源力扣)
- Prometheus安装并注册服务
- Collection of IOS development interview and underlying learning videos
- Flutter reports an error type 'Int' is not a subtype of type 'string' wonderful experience
- [deep learning] fast Reid tutorial
- Rounding in JS
- On the limit problem of compound function
- 二叉树初始化代码
- Wechat applet coordinate location interface usage (II) map interface
猜你喜欢
Few-shot Unsupervised Domain Adaptation with Image-to-Class Sparse Similarity Encoding
Mvcc and bufferpool (VI)
JVM virtual machine stack (III)
Linked list: orderly circular linked list
Linked list: the first coincident node of two linked lists
Image classification system based on support vector machine (Matlab GUI interface version)
Summary of the latest IOS interview questions in June 2020 (answers)
Vant框架中关于IndexBar索引栏的CDN单页面引用,无法正常展示
专业的数据库管理软件:Valentina Studio Pro for Mac
[data analysis and visualization] key points of data drawing 11- precautions for radar chart
随机推荐
Svg filter effect use
js多种判断写法
Introduction and download of common data sets for in-depth learning (with network disk link)
Modify the color of El input, textarea and El checkbox when they are disabled
Control scanner in Delphi
关于复合函数的极限问题
How to manage the IT R & D department?
Ijkplayer source code -- mnatemediaplayer of ijkmediaplayer
Scala implements workcount
PK of dotnet architecture
2019 - sorting out the latest and most comprehensive IOS test questions (including framework and algorithm questions)
Techniques for collecting stringgrid
On the limit problem of compound function
Traverse the array and delete an element until it is deleted
Introduction to redis (using redis, common commands, persistence methods, and cluster operations)
JMeter quick start
2022.05.29
遍历数组,删除某元素,直到删除为止
Using binary heap to implement priority queue
Install MySQL database