当前位置:网站首页>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) {
}
}
边栏推荐
- MySQL index bottom layer (I)
- Detailed explanation of data processing in machine learning (I) -- missing value processing (complete code attached)
- PK of dotnet architecture
- Hash table: whether alien languages are sorted
- Few-shot Unsupervised Domain Adaptation with Image-to-Class Sparse Similarity Encoding
- String: number of substring palindromes
- 如何挑选基金产品?什么样的基金是好基金?
- Collection of IOS development interview and underlying learning videos
- Entity framework extends the actual combat, small project reconfiguration, no trouble
- Svg filter effect use
猜你喜欢

Pycharm and Anaconda ultra detailed installation and configuration tutorial

MySQL 8.0 installation free configuration method

A wechat app for shopping

Professional database management software: Valentina Studio Pro for Mac
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)

MySQL index bottom layer (I)

六款国产飞机专用GPU产品通过鉴定审查

Installing the IK word breaker

Introduction to redis (using redis, common commands, persistence methods, and cluster operations)
![HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)](/img/c9/884aa008a185a471dfe252c0756fc1.png)
HEAP[xxx.exe]: Invalid address specified to RtlValidateHeap( 0xxxxxx, 0x000xx)
随机推荐
Keil去掉烦人的ST-Link更新提示
2022.05.29
Hash table: least recently used cache
Ijkplayer source code --- decode
Hash table: valid anagrams
Use and arrangement of wechat applet coordinate position interface (I)
JS deconstruction assignment
JMeter quick start
Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to
Hash table: the time complexity of insert, delete and random access is O (1)
[deep learning] fast Reid tutorial
Introduction to Sitemap_ Sitemap online generation and sorting
My practice of SOA architecture project based on WCF
最近最少使用缓存(来源力扣)
JS multiple judgment writing
Spark UDF instance details
Control scanner in Delphi
[life science] DNA extraction of basic biological experiments
【pytorch 记录】pytorch的变量parameter、buffer。self.register_buffer()、self.register_parameter()
CDN single page reference of indexbar index column in vant framework cannot be displayed normally