当前位置:网站首页>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");
}
}
边栏推荐
猜你喜欢
随机推荐
线性表之动态数组(ArrayList)的自实现
LeetCode_Dec_3rd_Week
深度学习理论——过拟合、欠拟合、正则化、优化器
基于语音识别的QT设计的csgo互动类视频游戏
LeetCode_Nov_1st_Week
管道重定向
C语言对文件的操作(完整版)
arm交叉编译
LeetCode_22_Apr_2nd_Week
关于DG(域泛化)领域的PCL方法的代码实例
代码庆端午--粽你心意
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
counting cycle
MNIST handwritten digit recognition - based on Mindspore to quickly build a perceptron to achieve ten categories
JDBC第一学之进行数据库连接时出现The server time zone.....解决办法
AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation
LeetCode_Nov_5th_Week
arm learning-1-development board
ideal life
tmux概念和使用









