设计模式七:责任链模式

news2024/9/30 3:29:36

文章目录

      • 1、责任链模式
      • 2、spring中的责任链模式
        • Spring Interceptor
        • Servlet Filter
        • Netty

1、责任链模式

责任链模式为请求创建了一个接收者对象的链,在这种模式下,通常每个节点都包含对另一个节点者的引用。每个节点针对请求,处理自己感兴趣的内容,处理完之后可以结束,也可以向下一个节点传递继续处理;

角色

  1. 抽象处理者角色:处理请求的抽象类,定义了处理请求的抽象方法;(抽象类或接口实现);
  2. 具体处理者角色:处理请求的具体实现类;(持有下家对象的引用);

例:请假流程都是先由本部门审核,根据时间长短再进行下一级审批

在这里插入图片描述

//抽象类
public abstract class Handler {
    /**
     * 请假天数
     */
    public int maxday;
    /**
     * 请假人
     */
    public String name;

    public Handler(String name, int maxday) {
        this.maxday = maxday;
        this.name = name;
    }

    private Handler nextHandler;

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    /**
     * 处理请假:判断请假天数,超过本部门限定时间则交由上一级部门
     */

    public final void handlingFakeSlips(int day) {
        if (this.maxday >= day) {
            this.agree(day);
        }
        else {
            if (nextHandler != null) {
                System.out.println(name+":天数已超过我的审批权限,已提交我的上级审批");
                nextHandler.handlingFakeSlips(day);
            }
            else {
                System.out.println("天数时间过长,准备辞职吧!!!");
            }
        }
    }

    /**
     * 审批动作:子类来实现
     * @param day
     */
    abstract void agree(int day);
}

//部门实现类
public class RDDepartment extends Handler{
    public RDDepartment(String name, int maxday) {
        super(name, maxday);
    }
    @Override
    void agree(int maxday) {
        System.out.println(name + ":研发部门请假审批通过,请假天数:" + maxday);
    }
}

//主管实现类
public class Supervisor extends Handler{
    public Supervisor(String name, int maxday) {
        super(name, maxday);
    }
    @Override
    void agree(int maxday) {
        System.out.println(name + ":主管请假审批通过,请假天数:" + maxday);
    }
}

//董事实现类
public class Director extends Handler{
    public Director(String name, int maxday) {
        super(name, maxday);
    }
    @Override
    void agree(int maxday) {
        System.out.println(name + ":请假董事审批通过,请假天数:" + maxday);
    }
}

//组装链
public class HandlerChain {
    private Handler head;
    private Handler tail;
    public HandlerContext(){
        RDDepartment rdDepartment = new RDDepartment("研发部门",5);
        Supervisor supervisor = new Supervisor("项目主管",30);
        Director director = new Director("董事",180);

        rdDepartment.setNextHandler(supervisor);
        supervisor.setNextHandler(director);

        head = rdDepartment;
        tail = director;
    }
    public void doHandler(Integer days){
        head.handlingFakeSlips(days);
    }
}


//请求
public class Request {
    public static void main(String[] args) {
        HandlerChain handlerChain = new HandlerChain();
        handlerChain.doHandler(360);
    }
}

优点(when,why):

​ 1.发送者与接收者之间的耦合度降低(解耦)

​ 2.可以灵活添加新的责任链中的对象

缺点:

​ 1.不能保证请求一定被接收

​ 2.一定程度上影响性能

这种形式很难进行动态新增和调整处理节点,一种比较复杂的控制节点的形式如Netty中的责任链模式应用,见下一节

2、spring中的责任链模式

Spring Interceptor

回顾springmvc处理请求的流程:DispatcherServlet接收到请求后,执行doDispatcher()方法,流程回顾请求处理流程图

其中通过HandlerMapping获得的是HandlerExecutionChain 对象

protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
    //......
    HandlerExecutionChain mappedHandler = null;
	//......
    mappedHandler = getHandler(processedRequest);
    //......     
    HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
	//......
}

protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
    if (this.handlerMappings != null) {
        for (HandlerMapping mapping : this.handlerMappings) {
            HandlerExecutionChain handler = mapping.getHandler(request);
            if (handler != null) {
                return handler;
            }
        }
    }
    return null;
}

protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletException {
    if (this.handlerAdapters != null) {
        for (HandlerAdapter adapter : this.handlerAdapters) {
            if (adapter.supports(handler)) {
                return adapter;
            }
        }
    }
    throw new ServletException("No adapter for handler [" + handler +
                               "]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler");
}

HandlerExecutionChain 中包含一个handler对象(后面匹配能处理handler的适配器对象执行,详情对应适配器模式中讲解),还有一个拦截器列表List<HandlerInterceptor> interceptorList,所有的实现了HandlerInterceptor接口的类都会被加载进这个集合中,在请求处理前后分别以责任链的形式调用拦截器的preHandlepostHandle

boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
        for (int i = 0; i < interceptors.length; i++) {
            HandlerInterceptor interceptor = interceptors[i];
            if (!interceptor.preHandle(request, response, this.handler)) {
                triggerAfterCompletion(request, response, null);
                return false;
            }
            this.interceptorIndex = i;
        }
    }
    return true;
}

void applyPostHandle(HttpServletRequest request, HttpServletResponse response, @Nullable ModelAndView mv)
    throws Exception {

    HandlerInterceptor[] interceptors = getInterceptors();
    if (!ObjectUtils.isEmpty(interceptors)) {
        for (int i = interceptors.length - 1; i >= 0; i--) {
            HandlerInterceptor interceptor = interceptors[i];
            interceptor.postHandle(request, response, this.handler, mv);
        }
    }
}

这里的链是由集合List维护,使用List有序的特性一次调用每个拦截器,通过方法返回的结果判断是否需要传递到下一个拦截器

Servlet Filter

servletFilter的调用也是通过责任链模式,通过FilterChain作为链条的管理者

//FilterChain接口
public interface FilterChain {
    public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
}

//FilterChain实现类
public class MockFilterChain implements FilterChain {
	
    //......
	private final List<Filter> filters;
	//......
    
	@Override
	public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
		Assert.notNull(request, "Request must not be null");
		Assert.notNull(response, "Response must not be null");
		Assert.state(this.request == null, "This FilterChain has already been called!");

		if (this.iterator == null) {
			this.iterator = this.filters.iterator();
		}

		if (this.iterator.hasNext()) {
			Filter nextFilter = this.iterator.next();
			nextFilter.doFilter(request, response, this);
		}

		this.request = request;
		this.response = response;
	}
}

由上可知,FilterChain中管理的 List<Filter> filters即为所有实现了Filter的过滤器,调用过滤器的时候,通过FilterChain进行链条的调用。


//Filter接口
public interface Filter {

    default public void init(FilterConfig filterConfig) throws ServletException {}

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
            throws IOException, ServletException;

    default public void destroy() {}
}

//Filter实现类
public class AuthFilter extends AuthenticationFilter {
   //......
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpRequest = toLowerCase((HttpServletRequest)request);
        String tokenString = httpRequest.getParameter("delegation");
        if (tokenString != null) {
            filterChain.doFilter(httpRequest, response);
        } else {
            super.doFilter(httpRequest, response, filterChain);
        }
    }
    //......
}

FilterdoFilter方法最后调用filterChain.doFilter(httpRequest, response);即传递至下一个Filter进行处理

Netty

Netty中的handler使用了责任链模式,但是其中回调过多,责任链模式的体现不清晰,参考该文章**Spring中如何使用责任链模式**,将责任链抽离出来,完成在spring中的调用


在这里插入图片描述

该模型中,具有多条链,每条链属于不同层级,链中节点为HandlerContextHandlerContext包含相邻接点的引用,还有Handler的引用

Pipeline:为链条的管理者,通过Pipeline来调用责任链

HandlerContext:为链条中节点的上下文,它里面有链条的前一个节点和后一个节点的HandlerContext引用

Handler: 具体的处理程序,与HandlerContext一一对应


我们先仅看Filter事件这一条链,整个结构由Pipeline管理整条链

在这里插入图片描述

//Pipelie接口
public interface Pipeline {
    Pipeline fireTaskFiltered();
}

//Pipeline实现类
Component("pipeline")
@Scope("prototype")
public class DefaultPipeline implements Pipeline, ApplicationContextAware, InitializingBean {
    // 创建一个默认的handler,将其注入到首尾两个节点的HandlerContext中,其作用只是将链往下传递
    private static final Handler DEFAULT_HANDLER = new Handler() {};

    // 将ApplicationContext注入进来的主要原因在于,HandlerContext是prototype类型的,因而需要
    // 通过ApplicationContext.getBean()方法来获取其实例
    private ApplicationContext context;

    // 创建一个头结点和尾节点,这两个节点内部没有做任何处理,只是默认的将每一层级的链往下传递,
    // 这里头结点和尾节点的主要作用就是用于标志整个链的首尾,所有的业务节点都在这两个节点中间
    private HandlerContext head;
    private HandlerContext tail;

    // 用于业务调用的request对象,其内部封装了业务数据
    private Request request;
    // 用于执行任务的task对象
    private Task task;

    // 最初始的业务数据需要通过构造函数传入,因为这是驱动整个pipeline所需要的数据,
    // 一般通过外部调用方的参数进行封装即可
    public DefaultPipeline(Request request) {
        this.request = request;
    }

    // 这里我们可以看到,每一层级的调用都是通过HandlerContext.invokeXXX(head)的方式进行的,
    // 也就是说我们每一层级链的入口都是从头结点开始的,当然在某些情况下,我们也需要从尾节点开始链
    // 的调用,这个时候传入tail即可。

    // 触发任务过滤的链调用
    @Override
    public Pipeline fireTaskFiltered() {
        HandlerContext.invokeTaskFiltered(head, task);
        return this;
    }

    // 用于往Pipeline中添加节点的方法,读者朋友也可以实现其他的方法用于进行链的维护
    void addLast(Handler handler) {
        HandlerContext handlerContext = newContext(handler);
        tail.prev.next = handlerContext;
        handlerContext.prev = tail.prev;
        handlerContext.next = tail;
        tail.prev = handlerContext;
    }

    // 这里通过实现InitializingBean接口来达到初始化Pipeline的目的,可以看到,这里初始的时候
    // 我们通过ApplicationContext实例化了两个HandlerContext对象,然后将head.next指向tail节点,
    // 将tail.prev指向head节点。也就是说,初始时,整个链只有头结点和尾节点。
    @Override
    public void afterPropertiesSet() throws Exception {
        head = newContext(DEFAULT_HANDLER);
        tail = newContext(DEFAULT_HANDLER);
        head.next = tail;
        tail.prev = head;
    }

    // 使用默认的Handler初始化一个HandlerContext
    private HandlerContext newContext(Handler handler) {
        HandlerContext context = this.context.getBean(HandlerContext.class);
        context.handler = handler;
        return context;
    }

    // 注入ApplicationContext对象
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.context = applicationContext;
    }
}

Pipeline的实现类内部除了实现接口的方法,其他方法均为初始化

  • DEFAULT_HANDLER: Pipeline管理一条链表,该链表的每个节点包含HandlerContextHandler两个对象, 而链表的首和尾两个节点由Pipeline自己指定(其他自定义的节点放在首尾两节点之间),DEFAULT_HANDLER用来作为首尾节点的Handler,不起任何作用
  • context: 由于这些类的作用域均不是单例,所以要使用ApplicationContext.getBean()方法获取,所以类实现了ApplicationContextAware接口的setApplicationContext方法,用于注入ApplicationContext对象
  • private HandlerContext head, tail: 为一条链的首尾两个节点,从这儿也可以看出,链条的每个节点都是通过HandlerContext来引用的,HandlerContext再引用一个Handler

@Component
@Scope("prototype")
public class HandlerContext {

    HandlerContext prev;
    HandlerContext next;
    Handler handler;

    private Task task;

    public void fireTaskFiltered(Task task) {
        invokeTaskFiltered(next(), task);
    }

    /**
     * 处理任务过滤事件
     */
    static void invokeTaskFiltered(HandlerContext ctx, Task task) {
        if (null != ctx) {
            try {
                ctx.handler().filterTask(ctx, task);
            } catch (Throwable e) {
                ctx.handler().exceptionCaught(ctx, e);
            }
        }
    }

    private HandlerContext next() {
        return next;
    }

    private Handler handler() {
        return handler;
    }
}

HandlerContext作为节点,应有前后两个节点的引用pre next,还有具体处理任务的Handler

fireTaskFiltered方法供Hanndler调用,将请求传递给下一个节点处理(方法实现中区下一个HandlerContext去执行)

invokeTaskFiltered静态方法供Pipeline 和 上一个节点的fireTaskFiltered方法调用,去执行Handler的方法


public interface Handler {
    /**
     * 查询到task之后,进行task过滤的逻辑
     */
    default void filterTask(HandlerContext ctx, Task task) {
        ctx.fireTaskFiltered(task);
    }
}

Handler定义了感兴趣的事件(暂时只看过滤事件)

Handler的实现类由我们根据自己的需要去编写,实现Handler接口即可

@Component
public class DurationHandler implements Handler {
    @Override
    public void filterTask(HandlerContext ctx, Task task) {
        System.out.println("时效性检验");
        ctx.fireTaskFiltered(task);
    }
}

@Component
public class RiskHandler implements Handler {
    @Override
    public void filterTask(HandlerContext ctx, Task task) {
        System.out.println("风控拦截");
        ctx.fireTaskFiltered(task);
    }
}

@Component
public class TimesHandler implements Handler {
    @Override
    public void filterTask(HandlerContext ctx, Task task) {
        System.out.println("次数限制检验");
        ctx.fireTaskFiltered(task);
    }
}

这里我们已经实现了PipelineHandlerContextHandler,知道这些bean都是被Spring所管理的bean,那么我们接下来的问题主要在于如何进行整个链的组装。这里的组装方式比较简单,其主要需要解决两个问题:

  • 对于后续写业务代码的人而言,其只需要实现一个Handler接口即可,而无需处理与链相关的所有逻辑,因而我们需要获取到所有实现了Handler接口的bean;
  • 将实现了Handler接口的bean通过HandlerContext进行封装,然后将其添加到Pipeline中。

以上可以由spring完成,通过生命实现接口BeanPostProcessor的类,实现postProcessAfterInitialization方法,可以在初始化完Pipeline后,获取所有实现了Handlerbean,并添加到pipeline中,spring自动调用该方法

@Component
public class HandlerBeanProcessor implements BeanPostProcessor, ApplicationContextAware {

    private ApplicationContext context;

    // 该方法会在一个bean初始化完成后调用,这里主要是在Pipeline初始化完成之后获取所有实现了
    // Handler接口的bean,然后通过调用Pipeline.addLast()方法将其添加到pipeline中
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        if (bean instanceof DefaultPipeline) {
            DefaultPipeline pipeline = (DefaultPipeline) bean;
            Map<String, Handler> handlerMap = context.getBeansOfType(Handler.class);
            handlerMap.forEach((name, handler) -> pipeline.addLast(handler));
        }

        return bean;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.context = applicationContext;
    }
}
  • postProcessAfterInitialization(Object bean, String beanName): 实现了BeanPostProcessor的该方法,在spring启动之后没初始化完成一个Bean之后,都会调用该方法

如此,当初始化完pipeline之后,获取实现了Handler接口的所有实现类,在addLast()方法中为每一个Handler初始化一个HandlerContext,并添加到Pipeline


如此下来,整个过程调用如下

@Service
public class ApplicationService {

    @Autowired
    private ApplicationContext context;

    public void mockedClient(Request request) {
        Pipeline pipeline = newPipeline(request);
        pipeline.fireTaskFiltered();
    }

    private Pipeline newPipeline(Request request) {
        return context.getBean(DefaultPipeline.class, request);
    }
}

1、spring项目启动,加载和初始化Bean,当加载到DefaultPipeline的时候,由于实现了InitializingBean接口,所以会调用初始化方法afterPropertiesSet(),为DefaultPipeline添加两个首尾节点HandlerContext

2、当初始化完成Pipeline之后,调用postProcessAfterInitialization(Object bean, String beanName);

3、加载所有实现了Hnadler接口的Bean,并通过pipeline.addLast(Handler handler方法为每一个handler创建一个HandlerContext,并添加到链条中;

至此形成了一条链

4、service想执行该链的时候,通过有参构造方法,将请求request传递给pipeline,调用pipeline.fireTaskFiltered();

5、pipeline.fireTaskFiltered()中,会调用HandlerContext的静态方法HandlerContext.invokeTaskFiltered(HandlerContext ctx, Task task)将第一个HandlerContext传入去执行,其handlerfilterTask(HandlerContext ctx, Task task)方法执行具体逻辑

6、handlerfilterTask(HandlerContext ctx, Task task)方法最后会调用ctxinvokeTaskFiltered(HandlerContext ctx, Task task)方法,该方法会使用invokeTaskFiltered(next(), task)去执行下一个节点ctx.handler().filterTask(ctx, task)

7、直至最后到节点tail没有下一个节点会停止执行;


至此单条链的责任链模式已完成

在netty中,并不是一条链,每一个handler有很多针对不同的事件的处理

在pipeline中有所有的事件,我们相对某一个事件处理是,实现handler的对应方法的处理逻辑,就会在对应层级的链中加入该handler,netty多层级代码责任链参考:Spring中如何使用责任链模式

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1485378.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

备战蓝桥杯---动态规划的一些思想1

话不多说&#xff0c;直接看题&#xff1a; 目录 1.双线程DP 2.正难则反多组DP 3.换个方向思考&#xff1a; 1.双线程DP 可能有人会说直接贪心&#xff1a;先选第1条的最优路径&#xff0c;再选第2条最优路径。 其实我们再选第1条时&#xff0c;我们怎么选会对第2条的路径…

宝塔面板安装各种组件以及部署应用服务

在linux服务器安装宝塔面板 一、从宝塔官网下载exe安装包&#xff0c;安装命令从宝塔官网&#xff08;https://www.bt.cn/&#xff09;获取 yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh二、安…

【JGit 】一个完整的使用案例

需求 生成一系列结构相同的项目代码&#xff0c;将这些项目的代码推送至一个指定的 Git 仓库&#xff0c;每个项目独占一个分支。 推送时若仓库不存在&#xff0c;则自动创建仓库。 分析 生成代码使用 Java 程序模拟&#xff0c;每个项目中模拟三个文件。Project.cpp 、Pro…

总结 HashTable, HashMap, ConcurrentHashMap 之间的区别

1.多线程环境使用哈希表 HashMap 不行,线程不安全 更靠谱的,Hashtable,在关键方法上加了synchronized 后来标准库又引入了一个更好的解决方案;ConcurrentHashMap 2.HashMap 首先HashMap本身线程不安全其次HashMap的key值可以为空&#xff08;当key为空时&#xff0c;哈希会…

FNM和SFNM的区别

看图说话。 级联模式下&#xff0c;FNM模式&#xff0c;从片的中断都是同一个级别&#xff0c;因此从片如果有多个中断发生&#xff0c;中断之间不会抢占&#xff0c;只能按顺序处理。 级连模式下&#xff0c;SFNM模式&#xff0c;从片中断有优先级的区别&#xff0c;高优先级…

Qt外部调用进程类QProcess的使用

有的时候我们需要在自己程序运行过程中调用其他进程&#xff0c;那么就需要用到QProcess。 首先可以了解一些关于进程的相关知识&#xff1a;线程与进程&#xff0c;你真得理解了吗_进程和线程的区别-CSDN博客 进程是计算机中的程序关于某数据集合上的一次运行活动&#xff0…

7.1.1 selenium介绍及安装chromedriver

目录 1. Selenium的用途 2. 安装Selenium库 3. 安装chromedriver 1. 查看谷歌版本号​编辑 2. 找到最新版本及下载 3. 配置环境变量 4. 检测是否配置成功 5. 用python初始化浏览器对象检测&#xff1a; 6. 参考链接 1. Selenium的用途 在前面我们提到&#xff1a;在我…

NIO核心三:Selector

一、基本概念 选择器提供一种选择执行已经就绪的任务的能力。selector选择器可以让单线程处理多个通道。如果程序打开了多个连接通道&#xff0c;每个连接的流量都比较低&#xff0c;可以使用Selector对通道进行管理。 二、如何创建选择器 1.创建Selector Selector select…

ArduinoTFTLCD应用

ArduinoTFTLCD应用 ArduinoTFTLCD应用硬件连接软件导入库显示数字、字符显示汉字方案1方案2 显示图片 总结 ArduinoTFTLCD应用 对于手工喜欢DIY的人来说&#xff0c;Arduino驱动的TFTLCD被很多人使用&#xff0c;此处就总结一下&#xff0c;使用的是VScode的PlatformIO插件驱动…

Docusaurus框架——react+antd+echarts自定义mdx生成图表代码解释文档

文章目录 ⭐前言⭐Docusaurus框架渲染mdx内容&#x1f496; 创建一个mdx文件&#x1f496; 创建一个react jsx文件&#x1f496; mdx引入react的组件并渲染&#x1f496; mdx引入react的组件源代码内容 ⭐渲染一个echarts地图的代码解释文档&#x1f496; echarts 渲染地图&…

USLE模型-P因子的计算

首先需要下载土地利用类型数据集&#xff0c;查看我的相关文章 对于已有的10种土地类型代码&#xff0c;需要按水土保持措施P值表进行重分类。 10是耕地&#xff0c;且庆阳市坡度10-15度左右&#xff0c;所以赋给了3&#xff08;最好再下个DEM计算一下&#xff0c;这里就统一用…

WebServer -- 注册登录

目录 &#x1f349;整体内容 &#x1f33c;流程图 &#x1f382;载入数据库表 提取用户名和密码 &#x1f6a9;同步线程登录注册 补充解释 代码 &#x1f618;页面跳转 补充解释 代码 &#x1f349;整体内容 概述 TinyWebServer 中&#xff0c;使用数据库连接池实现…

C++指针(三)

个人主页:PingdiGuo_guo 收录专栏&#xff1a;C干货专栏 文章目录 前言 1.字符指针 1.1字符指针的概念 1.2字符指针的用处 1.3字符指针的操作 1.3.1定义 1.3.2初始化 1.4字符指针使用注意事项 2.数组参数&#xff0c;指针参数 2.1数组参数 2.1.1数组参数的概念 2.1…

NCT 全国青少年编程图形化编程(Scratch)等级考试(一级)模拟测试H

202312 青少年软件编程等级考试Scratch一级真题 第 1 题 【 单选题 】 以下说法合理的是( ) A :随意点开不明来源的邮件 B :把密码设置成 abc123 C :在虚拟社区上可以辱骂他人 D :在改编他人的作品前&#xff0c; 先征得他人同意 正确答案&#xff1a; D 试题解析&…

python模块和包概念与使用

python模块和包概念与使用 Python模块与包的关键概念 在Python编程中&#xff0c;模块和包是代码组织和管理的基石。以下是关于Python模块与包的核心要点&#xff1a; 模块&#xff1a; 模块是一个包含Python代码的.py文件&#xff0c;它可以定义函数、类、变量等。通过导入模…

水经微图Web版1.6.0发布

让每一个人都有自己的地图&#xff01; 水经微图&#xff08;简称“微图”&#xff09;新版已上线&#xff0c;在该版本中主要新增了点线面图层分组样式设置、图层排序并按序绘制、KML支持矢量符号的存储、KML支持态势标绘要素存储和新增历史地图文本样式等。 现在&#xff0…

Leetcoder Day27| 贪心算法part01

语言&#xff1a;Java/Go 理论 贪心的本质是选择每一阶段的局部最优&#xff0c;从而达到全局最优。 什么时候用贪心&#xff1f;可以用局部最优退出全局最优&#xff0c;并且想不到反例到情况 贪心的一般解题步骤 将问题分解为若干个子问题找出适合的贪心策略求解每一个子…

使用plasmo框架开发浏览器插件,注入contents脚本和给页面添加UI组件

plasmo&#xff1a;GitHub - PlasmoHQ/plasmo: &#x1f9e9; The Browser Extension Framework plasmo是一个开发浏览器插件的框架&#xff0c;支持使用react和vue等技术&#xff0c;而且不用手动管理manifest.json文件&#xff0c;框架会根据你在框架中的使用&#xff0c;自…

美团分布式 ID 框架 Leaf 介绍和使用

一、Leaf 在当今日益数字化的世界里&#xff0c;软件系统的开发已经成为了几乎所有行业的核心。然而&#xff0c;随着应用程序的规模不断扩大&#xff0c;以及对性能和可扩展性的需求不断增加&#xff0c;传统的软件架构和设计模式也在不断地面临挑战。其中一个主要挑战就是如…

SAP EC-CS如何实现自动抵消

SAP EC-CS 是SAP 比较早的合并方案&#xff0c;尽管后面有很多其他的方案作为替代&#xff0c;但 EC-CS 因为其成熟性&#xff0c;在集团合并单元不多的情况下&#xff0c;也可以作为一个不错的合并解决方案。可以说&#xff0c;会计报表合并一个核心就是实现抵消的处理&#x…