From ba5063f69703441a68846229227b2890cf8765d1 Mon Sep 17 00:00:00 2001 From: xyiege Date: Thu, 14 Jul 2022 20:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=E4=B8=AD=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=20=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chjyj/szwh/controller/BaseController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/cn/chjyj/szwh/controller/BaseController.java b/src/main/java/cn/chjyj/szwh/controller/BaseController.java index 433be26..9b8bef7 100644 --- a/src/main/java/cn/chjyj/szwh/controller/BaseController.java +++ b/src/main/java/cn/chjyj/szwh/controller/BaseController.java @@ -1,11 +1,36 @@ package cn.chjyj.szwh.controller; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.Objects; /** * 基础控制器 */ public abstract class BaseController { + public static Log log = LogFactory.getLog(BaseController.class); // jsonobject 全局 protected JSONObject jsonObject=new JSONObject(); + + static { + RequestAttributes ra = RequestContextHolder.getRequestAttributes(); + if(Objects.isNull(ra)){ + log.debug("服务里RequestAttributes对象为空"); + }else{ + ServletRequestAttributes sra = (ServletRequestAttributes) ra; + HttpServletRequest request = sra.getRequest(); + // 查询请求头中的token + String token=request.getHeader("token"); + // 查询头部中的模块 + final String url=request.getHeader("url"); + } + + } + }