https://www.cnblogs.com/shuilangyizu/p/8621669.html
-
RequestContextHolder
顾名思义,持有上下文的Request容器。可以用来获取当前请求信息
package com.repository.manage.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* 获取当前请求信息
* @author km005
* @date 2019-12-09 3:33 下午
*/
@Slf4j
public class Current {
public static HttpServletRequest getRequest() {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
assert attributes != null;
return attributes.getRequest();
}
}
网友评论