package com.estate.expert.common.context; import javax.servlet.http.HttpServletRequest; import java.util.Optional; /** * http请求的context对象. 方便在服务层访问到http request信息. * @author code */ public class HttpRequestContext { private static ThreadLocal threadLocal = new InheritableThreadLocal(); public static void set(HttpServletRequest request) { threadLocal.set(request); } public static Optional get() { return Optional.ofNullable(threadLocal.get()); } public static void remove() { threadLocal.remove(); } }