Browse Source

控制器中查找 请求头

master
xyiege 4 years ago
parent
commit
ba5063f697
  1. 25
      src/main/java/cn/chjyj/szwh/controller/BaseController.java

25
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");
}
}
}

Loading…
Cancel
Save