Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3592955
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Java

2020-12-24 17:03:32

搭建项目

pom.xml配置

xsi:schemaLocation=" ">

4.0.0

 

org.springframework.boot

spring-boot-starter-parent

2.3.7.RELEASE

com.niu

springboot-interceptor

 1.0.0-SNAPSHOT

springboot-interceptor

springboot拦截器使用

 

1.8

 

 

org.springframework.boot

spring-boot-starter-web

 org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-maven-plugin

 

 

写一个控制器,加入一个接口

package com.niu.springbootinterceptor.controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

/**

* @description: 控制器

* @author: nxq email: niuxiangqian163@163.com

* @createDate: 2020/12/22 3:28 下午

* @updateUser: nxq email: niuxiangqian163@163.com

* @updateDate: 2020/12/22 3:28 下午

* @updateRemark:

* @version: 1.0 **/

@RestController

public class MyController {

@GetMapping("test")

public Object test(){

System.out.println("test接口");

 return "ok";}

编写拦截器

package com.niu.springbootinterceptor.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* @description: 拦截器

* @author: nxq email: niuxiangqian163@163.com

* @createDate: 2020/12/22 3:26 下午

* @updateUser: nxq email: niuxiangqian163@163.com

 * @updateDate: 2020/12/22 3:26 下午

* @updateRemark:

* @version: 1.0 **/

public class MyInterceptor  implements HandlerInterceptor {

 

阅读(2041) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~