当前位置:网站首页>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");
}
}
边栏推荐
- 动态内存管理-C语言
- Golang环境变量设置(二)--GOMODULE&GOPROXY
- Object.requireNonNull 方法说明
- MNIST Handwritten Digit Recognition - Image Analysis Method for Binary Classification
- LeetCode_22_Apr_4th_Week
- IEEE802.X protocol suite
- Tencent and NetEase have taken action one after another. What is the metaverse that is so popular that it is out of the circle?
- [daily office][ssh]cheatsheet
- [English learning][sentence] good sentence
- [Daily office][shell] Common code snippets
猜你喜欢
随机推荐
arm-2-基础阶段
counting cycle
file editor
Cut the hit pro subtitles export of essays
结构体传参-C语言
[Development Miscellaneous][Editor][Code Reading]ctags & vim
No matching function for call to 'RCTBridgeModuleNameForClass'
枚举和联合(自定义类型)-C语言
MVC自定义配置
const int * a 与 int * const a 的定义与区别
Copy Siege Lion's Annual "Battle" | Review 2020
基于asp.net的法律援助平台的设计与实现(附项目链接)
strlen 转义字符
Rules.make-适合在编辑模式下看
【C语言】数组名是什么
CSDN spree -- college round table spree
Deep Learning Theory - Initialization, Parameter Adjustment
EL表达式
彻底删除MySQL教程
file permission management ugo









