当前位置:网站首页>MVC custom configuration
MVC custom configuration
2022-08-04 06:36:00 【Louzen】
学习资料
MVC自定义配置
实现WebMvcConfigurer接口,并重写相关方法
自定义拦截器(Login interception as an example)
// 1、先定义一个拦截器,实现HandlerInterceptorInterface and implement the three methods inside
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进行自定义配置,重写addInterceptorsmethod to add a custom interceptor
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/", "/login");
}
}
边栏推荐
猜你喜欢
随机推荐
Chapter One Introduction
CAS无锁队列的实现
DRA821 环境搭建
MOOSE平台官方第二个例子分析——关于创建Kernel,求解对流扩散方程
Socket编程详解
target has libraries with conflicting names: libcrypto.a and libssl.a.
IDEA中创建web项目实现步骤
Pytest common plug-in
Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
LeetCode_Nov_5th_Week
(导航页)OpenStack-M版-双节点手工搭建-附B站视频
strlen 转义字符
C语言静态变量static的分析
在AWS-EC2中安装Minikube集群
迅雷关闭自动更新
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
How to grow into a senior engineer?
LeetCode_22_Apr_4th_Week
Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
线性表之动态数组(ArrayList)的自实现









