当前位置:网站首页>MVC自定义配置
MVC自定义配置
2022-08-04 05:31:00 【Louzen】
学习资料
MVC自定义配置
实现WebMvcConfigurer接口,并重写相关方法
自定义拦截器(登录拦截为例)
// 1、先定义一个拦截器,实现HandlerInterceptor接口并实现里面的三个方法
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return Objects.nonNull(request.getAttribute("loginUser"));
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
}
}
// 2、实现WebMvcConfigurer接口对web进行自定义配置,重写addInterceptors方法添加自定义拦截器
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/", "/login");
}
}
边栏推荐
- MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
- LeetCode_Nov_3rd_Week
- MOOSE平台官方第二个例子分析——关于创建Kernel,求解对流扩散方程
- tensorRT教程——使用tensorRT OP 搭建自己的网络
- bind()系统调用的用处
- Endnote编辑参考文献
- 【论文阅读】Multi-View Spectral Clustering with Optimal Neighborhood Laplacian Matrix
- 题目1000:输入两个整数a和b,计算a+b的和,此题是多组测试数据
- MNIST手写数字识别 —— ResNet-经典卷积神经网络
- yoloV5 使用——训练速度慢,加速训练
猜你喜欢
No matching function for call to 'RCTBridgeModuleNameForClass'
双向LSTM
典型CCN网络——efficientNet(2019-Google-已开源)
【深度学习日记】第一天:Hello world,Hello CNN MNIST
彻底删除MySQL教程
MFC读取点云,只能正常显示第一个,显示后面时报错
迅雷关闭自动更新
Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
Amazon Cloud Technology Build On-Amazon Neptune's Knowledge Graph-Based Recommendation Model Building Experience
target has libraries with conflicting names: libcrypto.a and libssl.a.
随机推荐
深度学习,“粮草”先行--浅谈数据集获取之道
Introduction to Convolutional Neural Networks
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
Comparison of oracle's number and postgresql's numeric
[开发杂项][编辑器][代码阅读]ctags&vim
YOLOV4流程图(方便理解)
【论文阅读】SPANET: SPATIAL PYRAMID ATTENTION NETWORK FOR ENHANCED IMAGE RECOGNITION
Copy Siege Lions "sticky" to AI couplets
Transformer
PCL窗口操作
MNIST handwritten digit recognition - based on Mindspore to quickly build a perceptron to achieve ten categories
tensorRT教程——tensor RT OP理解(实现自定义层,搭建网络)
tensorRT5.15 使用中的注意点
Deep learning, "grain and grass" first--On the way to obtain data sets
No matching function for call to ‘RCTBridgeModuleNameForClass‘
【Copy攻城狮日志】“一分钟”跑通MindSpore的LeNet模型
[开发杂项][调试]debug into kernel
MNIST手写数字识别 —— Lenet-5首个商用级别卷积神经网络
LeetCode_Dec_2nd_Week
latex-写论文时一些常用设置