C#学习笔记一 委托、事件

news2024/10/6 8:29:53

C# 委托、事件

在这里插入图片描述

1、Action委托、Func委托

namespace DelegateExample
{
    class Program
    {
        static void main(string[] args)
        {
            Calculator calculator=new Calculator();
            
            //Action委托
            Action Cal=new Action(calculator.Report);
            
            //直接调用函数
            Calculator.Report();
            //通过委托调用函数
            Cal.Invoke();
            //简便写法
            Cal();
            
            
            
            
            //Func委托
            int a=100,b=200,c=0;
          
            Func<int,int,int> func1=new Func<int,int,int>(Calculator.Add); 
            //尖括号中为<参数1,参数2,返回值>
            Func<int,int,int> func2=new Func<int,int,int>(Calculator.Sub);
            //利用委托调用函数
            c=func1.Invoke(a,b);//简便写法 c=func1(a,b)
            Console.WriteLine(c);
            
            c=func2.Invoke(a,b);//简便写法 c=func1(a,b)
            Console.WriteLine(c);
            
            
            
            
        }
    }
    class Calculator
    {
        public void  Report(){
            console.WriteLine("123");
        }
        public int Add(int a,int b){
            int result=a+b;
            return result;
        }
        public int Sub(int a,int b){
            int result=a-b;
            return result;
        }
    }

}


2、自定义委托

在这里插入图片描述

避免写错地方结果声明成嵌套类型:

​ 一般委托的声明在命名空间内,和Program类同级,如果声明在Program类中,会声明成为嵌套类 类型。

namespace DelegateExample
{
    //自定义委托声明格式
    public delegate double Cal(double x,double y);
    class Program
    {
     	static void main(string[] args){
            Calculator calculator=new Calculator();
            Cal cal1=new Cal(calculator.Add);
            Cal cal2=new Cal(calculator.Sub);
            Cal cal3=new Cal(calculator.Mul);
            Cal cal4=new Cal(calculator.Div);
		
            double a=200,b=100,c=0;
            c=cal1.invoke(a,b);
            Console.WriteLine(c);
            c=cal2.invoke(a,b);
            Console.WriteLine(c);
            c=cal3.invoke(a,b);
            Console.WriteLine(c);
            c=cal4.invoke(a,b);
            Console.WriteLine(c);
        }   
    }
    class Calculator
    {
        
        public double Add(double a,double b){
            return a+b;
        }
        public double Sub(double a,double b){
            return a-b;
        }
        public double Mul(double a,double b){
            return a*b;
        }
        public double Div(double a,double b){
            return a/b;
        }
    }
    
    
}

3、委托的一般使用

在这里插入图片描述

3.1 模板方法

using System;
using System.Collections.Generic;

namespace DelegateExample
{
    class Program
    {
        static void Main(string[] args)
        {
            WrapFactory wrapFactory = new WrapFactory();
            ProductFactory productFactory = new ProductFactory();

            Func<Product> func1 = new Func<Product>(productFactory.MakePizza);
            Func<Product> func2 = new Func<Product>(productFactory.MakeToyCar);

            Box box1 = wrapFactory.WrapProduct(func1);
            Box box2 = wrapFactory.WrapProduct(func2);

            Console.WriteLine(box1.Product.Name);
            Console.WriteLine(box2.Product.Name);

            Console.ReadKey();
        }
    }

    class Product
    {
        public string Name{ get; set; }
    }
    
    class Box
    {
        public Product Product { get; set; }
    }
    class WrapFactory
    {
        public Box WrapProduct(Func<Product> getProduct)
        {
            Product product = getProduct.Invoke();
            Box box = new Box();
            box.Product = product;
            return box;
        }
        
    }
    class ProductFactory
    {
        public Product MakePizza()
        {
            Product product = new Product();
            product.Name = "Pizza";
            return product;
        }
        public Product MakeToyCar()
        {
            Product product = new Product();
            product.Name = "Toy Car";
            return product;
        }
    }


}
//使用模板方法的好处,代码复用性高,只需要扩充ProductFactory类中的方法
//Product类、WrapFactory类,均不用修改

3.2 回调方法

需求:

使用委托的回调方法,在上述代码中实现,若产品价格大于等于50时,打印输出商品信息

using System;
using System.Collections.Generic;

namespace DelegateExample
{
    class Program
    {
        static void Main(string[] args)
        {
            WrapFactory wrapFactory = new WrapFactory();
            ProductFactory productFactory = new ProductFactory();

            Func<Product> func1 = new Func<Product>(productFactory.MakePizza);
            Func<Product> func2 = new Func<Product>(productFactory.MakeToyCar);

            Logger logger = new Logger();

            Action<Product> log = new Action<Product>(logger.Log);

            Box box1 = wrapFactory.WrapProduct(func1,log);
            Box box2 = wrapFactory.WrapProduct(func2,log);

            Console.WriteLine(box1.Product.Name);
            Console.WriteLine(box2.Product.Name);

            Console.ReadKey();
        }
    }
    
    class Logger
    {
        public void Log(Product product)
        {
            Console.WriteLine("Product '{0}' created at {1}. Price is {2}.", product.Name, DateTime.UtcNow, product.Price);
        }
    }
    class Product
    {
        public string Name{ get; set; }
        public double Price { get; set; }
    }
    
    class Box
    {
        public Product Product { get; set; }
    }
    class WrapFactory
    {
        public Box WrapProduct(Func<Product> getProduct,Action<Product> logCallback)
        {
            Product product = getProduct.Invoke();
            if (product.Price >= 50)
            {
                logCallback(product);
            }
            Box box = new Box();
            box.Product = product;
            return box;
        }
        
    }
    class ProductFactory
    {
        public Product MakePizza()
        {
            Product product = new Product();
            product.Name = "Pizza";
            product.Price = 20;
            return product;
        }
        public Product MakeToyCar()
        {
            Product product = new Product();
            product.Name = "Toy Car";
            product.Price = 99;
            return product;
        }
    }


}

3.3 委托的高级使用

同步与异步的概念:与中文不同

多播委托

using System;
using System.Collections.Generic;
using System.Threading;
namespace DelegateExample 
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { ID = 1, PenColor = ConsoleColor.Yellow };
            Student stu2 = new Student() { ID = 1, PenColor = ConsoleColor.Green };
            Student stu3 = new Student() { ID = 1, PenColor = ConsoleColor.Red };

            Action action1 = new Action(stu1.DoHomeWork);
            Action action2 = new Action(stu2.DoHomeWork);
            Action action3= new Action(stu3.DoHomeWork);
            //单播委托
            /*action1.Invoke();
            action2.Invoke();
            action3.Invoke();*/


            //多播委托
            action1 += action2;
            action1 += action3;
            action1.Invoke();


            Console.ReadKey();
        }
    }
    class Student
    {
        public int ID { get; set; }
        public ConsoleColor PenColor { get; set; }

       public void DoHomeWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.ForegroundColor = this.PenColor;
                Console.WriteLine("Student {0} doing homework {1} hour(s).", this.ID, i);
                Thread.Sleep(1000);
            }
        }

    }
    
    


}

隐式异步调用

​ 首先了解一下同步调用

​ 直接同步调用与间接同步调用

using System;
using System.Collections.Generic;
using System.Threading;
namespace DelegateExample 
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { ID = 1, PenColor = ConsoleColor.Yellow };
            Student stu2 = new Student() { ID = 1, PenColor = ConsoleColor.Green };
            Student stu3 = new Student() { ID = 1, PenColor = ConsoleColor.Red };

            //直接同步调用
            /*stu1.DoHomeWork();
            stu2.DoHomeWork();
            stu3.DoHomeWork();*/

            //间接同步调用
            Action action1 = new Action(stu1.DoHomeWork);
            Action action2 = new Action(stu2.DoHomeWork);
            Action action3 = new Action(stu3.DoHomeWork);

            action1.Invoke();
            action2.Invoke();
            action3.Invoke();
            //或者使用多播委托,也是同步调用的
            //action1+=action2;action1+=action3;action1.Invoke();
            

            for (int i = 0; i < 10; i++)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Main thread {0}.", i);
                Thread.Sleep(1000);
            }

            Console.ReadKey();
        }
    }
    class Student
    {
        public int ID { get; set; }
        public ConsoleColor PenColor { get; set; }

       public void DoHomeWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.ForegroundColor = this.PenColor;
                Console.WriteLine("Student {0} doing homework {1} hour(s).", this.ID, i);
                Thread.Sleep(1000);
            }
        }

    }
}

异步调用

​ 隐式异步调用

using System;
using System.Collections.Generic;
using System.Threading;
namespace DelegateExample 
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { ID = 1, PenColor = ConsoleColor.Yellow };
            Student stu2 = new Student() { ID = 1, PenColor = ConsoleColor.Green };
            Student stu3 = new Student() { ID = 1, PenColor = ConsoleColor.Red };

            
           
            //隐式异步调用
            Action action1 = new Action(stu1.DoHomeWork);
            Action action2 = new Action(stu2.DoHomeWork);
            Action action3 = new Action(stu3.DoHomeWork);
            action1.BeginInvoke(null,null);
            action2.BeginInvoke(null, null);
            action3.BeginInvoke(null, null);

            for (int i = 0; i < 10; i++)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Main thread {0}.", i);
                Thread.Sleep(1000);
            }

            Console.ReadKey();
        }
    }
    class Student
    {
        public int ID { get; set; }
        public ConsoleColor PenColor { get; set; }

       public void DoHomeWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.ForegroundColor = this.PenColor;
                Console.WriteLine("Student {0} doing homework {1} hour(s).", this.ID, i);
                Thread.Sleep(1000);
            }
        }

    }
    
    


}

显式异步调用(古老的方式:使用Thread进行显示异步调用)

using System;
using System.Collections.Generic;
using System.Threading;
namespace DelegateExample 
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { ID = 1, PenColor = ConsoleColor.Yellow };
            Student stu2 = new Student() { ID = 1, PenColor = ConsoleColor.Green };
            Student stu3 = new Student() { ID = 1, PenColor = ConsoleColor.Red };


            /*            
            Action action1 = new Action(stu1.DoHomeWork);
            Action action2 = new Action(stu2.DoHomeWork);
            Action action3 = new Action(stu3.DoHomeWork);

            //隐式异步调用
            action1.BeginInvoke(null,null);
            action2.BeginInvoke(null, null);
            action3.BeginInvoke(null, null);
            */

            //使用Thread进行显式异步调用
            Thread thread1 = new Thread(new ThreadStart(stu1.DoHomeWork));
            Thread thread2 = new Thread(new ThreadStart(stu2.DoHomeWork));
            Thread thread3 = new Thread(new ThreadStart(stu3.DoHomeWork));

            thread1.Start();
            thread2.Start();
            thread3.Start();

            for (int i = 0; i < 10; i++)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Main thread {0}.", i);
                Thread.Sleep(1000);
            }

            Console.ReadKey();
        }
    }
    class Student
    {
        public int ID { get; set; }
        public ConsoleColor PenColor { get; set; }

       public void DoHomeWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.ForegroundColor = this.PenColor;
                Console.WriteLine("Student {0} doing homework {1} hour(s).", this.ID, i);
                Thread.Sleep(1000);
            }
        }

    }
}

显式异步调用更高级的方式:Task,需要引用System.Threading.Tasks命名空间

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace DelegateExample 
{
    class Program
    {
        public static object TTask { get; private set; }

        static void Main(string[] args)
        {
            Student stu1 = new Student() { ID = 1, PenColor = ConsoleColor.Yellow };
            Student stu2 = new Student() { ID = 1, PenColor = ConsoleColor.Green };
            Student stu3 = new Student() { ID = 1, PenColor = ConsoleColor.Red };


            /*            
            Action action1 = new Action(stu1.DoHomeWork);
            Action action2 = new Action(stu2.DoHomeWork);
            Action action3 = new Action(stu3.DoHomeWork);

            //隐式异步调用
            action1.BeginInvoke(null,null);
            action2.BeginInvoke(null, null);
            action3.BeginInvoke(null, null);
            */

            //使用Thread进行显式异步调用
            /*Thread thread1 = new Thread(new ThreadStart(stu1.DoHomeWork));
            Thread thread2 = new Thread(new ThreadStart(stu2.DoHomeWork));
            Thread thread3 = new Thread(new ThreadStart(stu3.DoHomeWork));

            thread1.Start();
            thread2.Start();
            thread3.Start();*/

            //更高级的方式,使用Task进行显式异步调用
            Task task1 = new Task(new Action(stu1.DoHomeWork));
            Task task2 = new Task(new Action(stu2.DoHomeWork));
            Task task3 = new Task(new Action(stu3.DoHomeWork));

            task1.Start();
            task2.Start();
            task3.Start();


            for (int i = 0; i < 10; i++)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Main thread {0}.", i);
                Thread.Sleep(1000);
            }

            Console.ReadKey();
        }
    }
    class Student
    {
        public int ID { get; set; }
        public ConsoleColor PenColor { get; set; }

       public void DoHomeWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.ForegroundColor = this.PenColor;
                Console.WriteLine("Student {0} doing homework {1} hour(s).", this.ID, i);
                Thread.Sleep(1000);
            }
        }

    }
}

最好用接口代替委托

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Mhj2pXf5-1670512875811)(C:\Users\Wu\AppData\Roaming\Typora\typora-user-images\image-20221208185431055.png)]

用接口代替第一个案例中的委托

using System;
using System.Collections.Generic;

namespace DelegateExample
{
    class Program
    {
        static void Main(string[] args)
        {

            IProductFactory pizzaFactory = new PizzaFactory();
            IProductFactory toyCarFactory = new ToyCarFactory();
            WrapFactory wrapFactory = new WrapFactory();
            
            
            Box box1 = wrapFactory.WrapProduct(pizzaFactory);
            Box box2 = wrapFactory.WrapProduct(toyCarFactory);

            Console.WriteLine(box1.Product.Name);
            Console.WriteLine(box2.Product.Name);

            Console.ReadKey();
        }
    }

    interface IProductFactory
    {
        Product Make();
    }
    class PizzaFactory : IProductFactory
    {
        public Product Make()
        {
            Product product = new Product();
            product.Name = "Pizza";
            return product;
        }
    }
    class ToyCarFactory : IProductFactory
    {
        public Product Make()
        {
            Product product = new Product();
            product.Name = "Toy Car";
            return product;
        }
            
    }

    class Product
    {
        public string Name { get; set; }
        public double Price { get; set; }
    }

    class Box
    {
        public Product Product { get; set; }
    }
    class WrapFactory
    {
        public Box WrapProduct(IProductFactory productFactory)
        {
            Product product = productFactory.Make();
            Box box = new Box();
            box.Product = product;
            return box;
        }

    }
}

事件

1.初步了解

在这里插入图片描述

在这里插入图片描述
统一称为事件的订阅者

在这里插入图片描述
统一称为事件参数

2.动手操作
在这里插入图片描述

1.事件的简单示例

using System;
using System.Timers;
namespace EventExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Timer timer = new Timer();//timer为事件的拥有者
            timer.Interval = 1000;
            Boy boy = new Boy();//boy为事件的订阅者
            Girl girl = new Girl();
            timer.Elapsed += boy.Action;
            timer.Elapsed += girl.Action;
            timer.Start();
            Console.ReadLine();
        }
    }
    class Boy
    {
        internal void Action(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine("Jump!");
        }
    }

    class Girl
    {
        internal void Action(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine("Sing!");
        }
    }

}
  1. 示例2

在这里插入图片描述

using System;
using System.Windows.Forms;

namespace EventExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Form form = new Form();//form是事件的拥有者
            Controller controller = new Controller(form);//controller是事件的订阅者
            form.ShowDialog();
        }
    }
    
    class Controller
    {
        private Form form;
        public Controller(Form form)
        {
            if (form != null)
            {
                this.form = form;
                this.form.Click += this.FormClicked;//form.Click是事件成员,FromClicked是事件处理器
            }
        }

        private void FormClicked(object sender, EventArgs e)
        {
            this.form.Text = DateTime.Now.ToString();
        }
    }
}

3.示例3
在这里插入图片描述

using System;
using System.Windows.Forms;

namespace EventExample
{
    class Program
    {
        static void Main(string[] args)
        {
            MyForm form = new MyForm();//form事件拥有者
            form.Click += form.FormClicked;//事件成员form.Click;事件处理器form.FormClicked;
                                           //事件订阅者也是form;
            form.ShowDialog();
        }
    }
    class MyForm : Form
    {
        internal void FormClicked(object sender, EventArgs e)
        {
            this.Text = DateTime.Now.ToString();
        }
    }
}

4.示例4

using System;
using System.Windows.Forms;

namespace EventExample
{
    class Program
    {
        static void Main(string[] args)
        {
            MyForm form = new MyForm();
            form.ShowDialog();
        }
       
    }
    
    class MyForm : Form
    {
        private TextBox textBox;
        private Button button;//事件拥有者是实例化的 Form.button
        public MyForm()
        {
            this.textBox = new TextBox();
            this.button = new Button();
            this.Controls.Add(this.button);
            this.Controls.Add(this.textBox);
            this.button.Click += ButtonClicked;//button.Click是事件成员,
                                               //ButtonClicked是事件处理器
                                               //事件订阅者是MyForm的实例
        }

        private void ButtonClicked(object sender, EventArgs e)
        {
            this.textBox.Text = "Hello, World!";
        }
    }
}

委托、事件

  • C# 委托、事件
    • 1、Action委托、Func委托
    • 2、自定义委托
    • 3、委托的一般使用
      • 3.1 模板方法
      • 3.2 回调方法
      • 3.3 委托的高级使用
        • 同步与异步的概念:与中文不同
        • 多播委托
        • **隐式异步调用**
        • **异步调用**
      • 最好用接口代替委托
  • 事件

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

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

相关文章

艾美捷RPMI-1640培养基含L-谷氨酰胺的功能和研究

Roswell Park Memorial Institute (RPMI) 1640 培养基起初是为了悬浮培养人白血病单层细胞而开发的。RPMI 1640 培养基被发现适用于多种哺乳动物细胞&#xff0c;包括 HeLa 细胞、Jurkat 细胞、MCF-7 细胞、PC12 细胞、PBMC 细胞、星形胶质细胞和癌细胞。针对广泛的细胞培养应用…

阿里影业的稳健业绩来源:科技+内容塑造韧性,应对市场变化

随着《阿凡达&#xff1a;水之道》&#xff08;简称&#xff1a;《阿凡达2》&#xff09;预售佳绩的显现&#xff0c;电影业的复苏已然箭在弦上。 12月7日&#xff0c;《阿凡达2》正式开启预售&#xff0c;灯塔专业版数据显示&#xff0c;其预售开启4小时后&#xff0c;总票房…

【工作随笔】验证经验、维度

背景&#xff1a;目前负责模块的验证工作基本进展完毕&#xff0c;包括所有功能验证、场景覆盖、用例编写调试和仿真、功能覆盖率收集、sva检测时序等&#xff0c;在当前的进度上和开发、验证同时对我的工作进行了评审。 问题&#xff1a;在评审中间讨论到一个当前tc实现的问题…

五、卷积神经网络CNN7(图像卷积与反卷积)

图像卷积 首先给出一个输入输出结果那他是怎样计算的呢&#xff1f; 卷积的时候需要对卷积核进行 180 的旋转&#xff0c;同时卷积核中心与需计算的图像像素对齐&#xff0c;输出结构为中心对齐像素的一个新的像素值&#xff0c;计算例子如下&#xff1a;这样计算出左上角(即第…

基于Dijkstra和A算法的机器人路径规划附Matlab代码

✅作者简介&#xff1a;热爱科研的Matlab仿真开发者&#xff0c;修心和技术同步精进&#xff0c;matlab项目合作可私信。 &#x1f34e;个人主页&#xff1a;Matlab科研工作室 &#x1f34a;个人信条&#xff1a;格物致知。 更多Matlab仿真内容点击&#x1f447; 智能优化算法 …

JAVA SCRIPT设计模式--行为型--设计模式之Observer观察者模式(19)

JAVA SCRIPT设计模式是本人根据GOF的设计模式写的博客记录。使用JAVA SCRIPT语言来实现主体功能&#xff0c;所以不可能像C&#xff0c;JAVA等面向对象语言一样严谨&#xff0c;大部分程序都附上了JAVA SCRIPT代码&#xff0c;代码只是实现了设计模式的主体功能&#xff0c;不代…

Python图像识别实战(一):实现按比例随机抽取图像移动到另一文件夹

前面我介绍了可视化的一些方法以及机器学习在预测方面的应用&#xff0c;分为分类问题&#xff08;预测值是离散型&#xff09;和回归问题&#xff08;预测值是连续型&#xff09;&#xff08;具体见之前的文章&#xff09;。 从本期开始&#xff0c;我将做一个关于图像识别的…

Nacos集群搭建

1、下载nacos http://t.csdn.cn/ejfu9 2、配置Nacos 进入nacos的conf目录&#xff0c;修改配置文件cluster.conf.example&#xff0c;重命名为cluster.conf&#xff1a; 然后添加内容&#xff1a; 添加的内容是你要启动的多台nacos的IP和端口 127.0.0.1:8845 127.0.0.1:8846…

如何批量注册推特账号

Twitter推特账号怎么注册&#xff1f;相信国内好多朋友都被推特注册卡住&#xff0c;不知怎么注册twitter账号&#xff0c;由于国内限制的问题&#xff0c;推特账号注册比以前更麻烦了&#xff0c;本文将详细讲解Twitter怎么注册&#xff0c;Twitter (推特)是一个广受欢迎的社交…

【C#基础学习】第十五章、结构

目录 结构 1.结构的构造函数 1.1 实例构造函数 1.2 静态构造函数 1.3 总结 2.结构体作为返回值和参数 结构 结构的定义&#xff1a;结构是一种可以由程序员自定义的密封的值类型。 结构与类的区别&#xff1a;结构与类类似&#xff0c;它们都有自己的数据成员和函数成员。…

Nginx篇之实现反向代理和端口转发

一、前言 在正式生产环境中&#xff0c;web服务器、反向代理服务器的选择大都会选择nginx&#xff0c;确实&#xff0c;在常见的高并发场景下&#xff0c;nginx能够支持以万为单位的并发请求量&#xff0c;并且服务性能稳定&#xff0c;应用极为广泛。 二、反向代理含义 反向代…

【LeetCode_字符串_中心扩散 】5. 最长回文子串

目录考察点第一次&#xff1a;2022年12月8日10:29:05解题思路代码展示&#xff1a;中心扩散题目描述5. 最长回文子串 给你一个字符串 s&#xff0c;找到 s 中最长的回文子串。 示例 1&#xff1a; 输入&#xff1a;s "babad" 输出&#xff1a;"bab" 解…

高通平台开发系列讲解(Camera篇)新增GC8034摄像头步骤

文章目录 一、新增配置文件二、配置摄像头三、设置效果文件四、修改设备树五、修改用户空间驱动程序沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇章主要介绍高通平台新增摄像头步骤。 一、新增配置文件 在vendor/qcom/proprietary/common/config/device-vendor.…

一文读懂数据加密

文章目录本文前言一、可逆加密1.1 对称加密&#xff08;传统加密算法&#xff09;1.2 非对称加密&#xff08;现代加密算法&#xff09;二、不可逆加密三、 混合加密、消息摘要和数字签名四、文章最后本文前言 在计算机信息安全领域&#xff0c;之前软件设计师的网络安全部分了…

解决Elasticsearch Connection reset by peer异常

一、问题现象 随着ES的密集使用&#xff0c;线上环境&#xff0c;不同应用最近几天陆续有报java.io.IOException: Connection reset by peer异常&#xff0c;感觉不太正常。直接影响就是用户查询或者变更ES数据失败。 java.io.IOException: Connection reset by peerat org.e…

大数据:Storm集成HDFS和HBase

一、Storm集成HDFS 1.1 项目结构 1.2 项目主要依赖 项目主要依赖如下&#xff0c;有两个地方需要注意&#xff1a; 这里由于我服务器上安装的是 CDH 版本的 Hadoop&#xff0c;在导入依赖时引入的也是 CDH 版本的依赖&#xff0c;需要使用 <repository> 标签指定 CDH …

自适应且不可删除的水印蒙层

目录 canvas自适应文字长度&#xff0c;旋转角度生成水印背景图 生成蒙层 禁止蒙层的删除和修改 canvas自适应文字长度&#xff0c;旋转角度生成水印背景图 设置canvas字体大小后&#xff0c;通过ctx.measureText(text).width获取两行文字的宽度text1&#xff0c;text2&…

python-(6-5-1)爬虫---xpath解析实战

文章目录一 环境准备二 需求三 分析1 拿到页面源代码2 提取和解析数据四 步骤流程1 拿到页面源代码2 提取和解析数据五 完整代码xpath是在XML文档中搜索内容的一门语言 html是xml的一个子集 一 环境准备 安装lxml模块 二 需求 爬取某网站的数据 三 分析 1 拿到页面源代码 …

计算机领域热知识【2】消息队列与celery

Celery是实现消息队列的一个工具&#xff0c;本篇博客将介绍消息队列的基础知识&#xff0c;以及celery实现消息队列的总体方法。想要实现用Celery实现消息队列实例的朋友&#xff0c;可以从本篇博客中找到我写的另一篇介绍使用Celery和RabbitMQ实现消息队列的博客。 目录消息队…

Java+Swing+mysql天气信息管理系统

JavaSwingmysql天气信息管理系统一、系统介绍二、功能展示1.主要功能2.主页3.查询历史天气三、数据库四、其他系统一、系统介绍 该系统实现: 通过高德天气API查询天气数据 将查询的数据存入本地数据库 删除数据。 二、功能展示 1.主要功能 2.主页 3.查询历史天气 三、数据库…