首页 > 其他分享 >springboot拦截器

springboot拦截器

时间:2022-09-19 11:35:29浏览次数:68  
标签:拦截器 springboot springframework org import servlet public name

package com.module.interceptor;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 轮转
 * @date 2022/9/13
 * @description
 */
@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {

    @Data
    class Interceptor implements HandlerInterceptor {

        private String name;

        public Interceptor(String name) {
            this.name = name;
        }

        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            log.info("我是拦截器:" + name);
            return true;
        }
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        for (int i = 0; i < 10; i++) {
            registry.addInterceptor(new Interceptor(i + "号"));
        }
    }
}

 

标签:拦截器,springboot,springframework,org,import,servlet,public,name
From: https://www.cnblogs.com/yyqlz/p/16707156.html

相关文章

  • springboot内置tomcat配置本地文件夹的映射路径
    例如要访问的本地路径是D盘下的PersonalHomePage目录的某个图片1importorg.springframework.context.annotation.Configuration;2importorg.springframework.web.......
  • springboot中解析JSON参数
    解析psot请求中的JSON参数Map<String,String>attrMap=newHashMap<String,String>();BufferedReaderstreamReader=null;try{streamReader=newBufferedRead......
  • Java【SpringBoot】——添加测试依赖
    在pom.xml添加依赖1<dependency>2<groupId>org.springframework.boot</groupId>3<artifactId>spring-boot-starter-test</artifactId>......
  • springboot集成mybatis获取插入数据的主键
    问题:我们想在插入一条数据后同时能够返回这条数据在表中的id,Mybatis提供了@SelectKey注解。student为数据表,主键自增SelectKey的四个属性:selectKey会将SELECTLAS......
  • SpringBoot集成Mybatis 实现InsertOrUpdate功能
    需求场景在项目开发过程中,难免会遇到这样的场景:对一张表,当数据不存在的时候,进行insert插入操作;数据存在的时候,进行update更新操作;下面就来使用Mybatis的InsertOrUpdate功......
  • springboot代码生成器
    一、使用springboot+mybatisplus+swagger完成如下操作1、创建数据库表如下channel字段名称中文类型长度主键外键自增约束cid栏目id......
  • springboot Condition 动态value
    packagecom.example.demo.condtion;importorg.springframework.context.annotation.Conditional;importjava.lang.annotation.*;@Target({ElementType.TYPE,Ele......
  • springboot Condition
    packagecom.example.demo.config;importcom.example.demo.condtion.ClassCondition;importcom.example.demo.domian.User;importorg.springframework.context.an......
  • 【博学谷学习记录】超强总结,用心分享 。SpringBoot 常用注解
    @RequestMapping@RequestMapping注解的主要用途是将Web请求与请求处理类中的方法进行映射。SpringMVC和SpringWebFlux都通过RquestMappingHandlerMapping和RequestMappi......
  • Spring常用注解 以及 SpringBoot常用注解
    Spring常用注解以及SpringBoot常用注解既然提到了这个概念,那就从Spring先说起.SpringBoot就是封装后的Spring,相对于Spring,Boot省去了很多配置,也是很好的解决......