美文网首页
RequestContextHolder

RequestContextHolder

作者: 荒天帝886 | 来源:发表于2019-12-09 15:39 被阅读0次

    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();
        }
    }
    

    相关文章

      网友评论

          本文标题:RequestContextHolder

          本文链接:https://www.haomeiwen.com/subject/xhobgctx.html