当前位置: 首页 > wzjs >正文

哪里有网站制作多用户商城数据库设计

哪里有网站制作,多用户商城数据库设计,好品牌设计公司,做词云的网站前言 本文针对已经了解了ThreadLocal的读者 本文将会运用threadLocal给出完整的需要在一个上下文中传递全局参数 如userInfo 信息的解决方案 基本思路: 1、定义ThreadContext 作为底层“线程隔离存储容器” 2、基于ThreadContext 衍生出多个特定场景的业务封装类&…

前言

本文针对已经了解了ThreadLocal的读者 本文将会运用threadLocal给出完整的需要在一个上下文中传递全局参数 如userInfo 信息的解决方案

基本思路:

1、定义ThreadContext 作为底层“线程隔离存储容器”
2、基于ThreadContext 衍生出多个特定场景的业务封装类(Context 工具类)
3、新增一个业务上下文,只需加一个封装类,不改底层逻辑

ThreadContext

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;public final class ThreadContext {private static final ThreadLocal<Map<String, Object>> THREAD_LOCAL = new ThreadLocal();public ThreadContext() {}public static <T> T getAttribute(String key) {return getNotInheritableAttributes().get(key);}private static Map<String, Object> getNotInheritableAttributes() {Map<String, Object> attributes = (Map)THREAD_LOCAL.get();if (attributes == null) {attributes = new ConcurrentHashMap(32);THREAD_LOCAL.set(attributes);}return (Map)attributes;}public static void setNotInheritableAttribute(String key, Object value) {Assert.notBlank(key, "ThreadLocal的key不能为空!", new Object[0]);Assert.notNull(value, "ThreadLocal的value不能为空!", new Object[0]);getNotInheritableAttributes().put(key, value);}public static void setNotInheritableAttributes(Map<String, ?> attributes) {Assert.notEmpty(attributes, "ThreadLocal的参数不能为空!", new Object[0]);getNotInheritableAttributes().putAll(attributes);}public static void removeAttribute(String key) {Assert.notBlank(key, "key不能为空!", new Object[0]);getNotInheritableAttributes().remove(key);}public static void clearAttributes() {THREAD_LOCAL.remove();}
}

然后就可以基于ThreadContext 根据不同的业务衍生不同的Context 工具类

UserContext

public class UserContext {public static void setUserInfo(User user) {ThreadContext.setNotInheritableAttribute("USER_INFO", user);}public static User getUserInfo() {User user = (User)ThreadContext.getAttribute("USER_INFO");if (user == null) {throw new IllegalArgumentException("无法获取登录用户信息!");} else {return user;}}public static boolean hasUserInfo() {return ThreadContext.containsAttribute("USER_INFO");}public static void clear() {ThreadContext.removeAttribute("USER_INFO");}
}

任意类型的XXContext


public class BusinessContext {private static final String KEY = "business";public static void setBusiness(String info) {ThreadContext.setNotInheritableAttribute(KEY, info);}public static String getBusiness() {return (String)ThreadContext.getAttribute(KEY);}public static void clear() {ThreadContext.removeAttribute(KEY);}
}

总结

ThreadContext 管理存取逻辑

UserContext / BusinessContext 等专注业务字段

可复用、易拓展

新增一个业务上下文,只需加一个封装类,不改底层逻辑。


文章转载自:

http://a5FhnXPR.drjLL.cn
http://helD44b3.drjLL.cn
http://IYfKraRk.drjLL.cn
http://IWbIeHef.drjLL.cn
http://uCQFSV7G.drjLL.cn
http://9ScPKO7A.drjLL.cn
http://A1RBh1Cw.drjLL.cn
http://XlsbLZZg.drjLL.cn
http://KNOlHxgH.drjLL.cn
http://7mIJ1YZl.drjLL.cn
http://8SSGAa6j.drjLL.cn
http://igUDTMvv.drjLL.cn
http://i20ALjng.drjLL.cn
http://iTtKZEnw.drjLL.cn
http://Jr6rtLa8.drjLL.cn
http://kSxieQFe.drjLL.cn
http://0MIe6VIW.drjLL.cn
http://7Yw7xIX2.drjLL.cn
http://iT46VE7P.drjLL.cn
http://aaq2dSRr.drjLL.cn
http://CpDX7rr2.drjLL.cn
http://oHORFzIP.drjLL.cn
http://wirTaaXs.drjLL.cn
http://WszvOXBM.drjLL.cn
http://KFk45krN.drjLL.cn
http://84uenlcY.drjLL.cn
http://IevaUUQv.drjLL.cn
http://DPxq1LTi.drjLL.cn
http://YaJ4aTvn.drjLL.cn
http://rbjzzaQ6.drjLL.cn
http://www.dtcms.com/wzjs/762471.html

相关文章:

  • 如何用电脑做网站服务器创意设计网站推荐
  • 滕州网站建设推广帝国cms这么做网站
  • 沧州英文模板建站鲁班设计工作平台
  • 网站推广公司 wordpress网络电话免费版
  • 深圳网站建设 龙华信科黑蜘蛛网站
  • 浏览wap网站制作免费个人网页
  • 网站如何做线上和线下推广南昌做seo的公司有哪些
  • 自适应网站系统吗巩义网站优化公司
  • 东莞市官网网站建设哪家好网站网业设计
  • 如何做网站链接分享朋友圈赣州seo优化
  • 商城类网站建设数据库mp3链接地址制作网站
  • 房产网站模板程序wordpress head文件夹
  • 没有备案的网站使用微信泊头网站优化
  • 上海网站开发工程师金华免费模板建站
  • 学校网站建设计划书wordpress 代码解读
  • wordpress 手机 登陆百度seo2022
  • 建设部政务网站网站模板库 下载
  • 手机上能不能制作网站开发网站建设的定位
  • 装修设计网站免费wordpress自定义下载
  • 建站网站排行赣州seo公司
  • 如何注册网站免费的吗网站设计步骤及注意事项
  • 网站运营服务商房屋装修设计图片欣赏
  • 怎么选择移动网站建设个人做网站开工作室
  • 南宁住房和城乡建设部网站用哪个程序做网站收录好6
  • h5个人网站代码织梦网站访问量统计代码
  • 开发高端网站开发宁波易企网做的网站
  • 医院门户网站设计dream8网站建设教程视频
  • 甘肃网站建设制作商建立一个网站的步骤
  • 企业网站都需要备案吗开化网站建设公司
  • 购买网域名的网站好免费代刷网站推广