获取全局id

package com.itheima.common;

public class BaseContext {
//session存储的id值无法在过滤器中获取到,要用ThreadLocal一次线程中都能获取
private static final ThreadLocal<Long> threadLocalId =new ThreadLocal<Long>();
public static void setThreadLocalId(Long id){
threadLocalId.set(id);
}

public static Long getThreadLocalId() {

Long aLong = threadLocalId.get();
return aLong;
}
}
posted @ 2022-07-20 23:19  pengkangwzw  阅读(21)  评论(0)    收藏  举报