分类: Java
2020-12-24 17:03:32
搭建项目
pom.xml配置
xsi:schemaLocation=" ">
写一个控制器,加入一个接口
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 {