重学Java设计模式-行为型模式-中介者模式

news2024/9/19 10:19:25

重学Java设计模式-行为型模式-中介者模式

内容摘自:https://bugstack.cn/md/develop/design-pattern/2020-06-27-重学 Java 设计模式《实战中介者模式》.html#重学-java-设计模式-实战中介者模式「按照mybatis原理手写orm框架-给jdbc方式操作数据库增加中介者场景」

中介者模式介绍

中介者模式,图片来自 refactoringguru.cn

  • 图片来自:https://refactoringguru.cn/design-patterns/mediator(opens new window)

中介者模式要解决的就是复杂功能应用之间的重复调用,在这中间添加一层中介者包装服务,对外提供简单、通用、易扩展的服务能力。

这样的设计模式几乎在我们日常生活和实际业务开发中都会见到,例如;飞机🛬降落有小姐姐在塔台喊话、无论哪个方向来的候车都从站台上下、公司的系统中有一个中台专门为你包装所有接口和提供统一的服务等等,这些都运用了中介者模式。除此之外,你用到的一些中间件,他们包装了底层多种数据库的差异化,提供非常简单的方式进行使用。

案例场景模拟

场景模拟;模仿Mybatis手写ORM框架

在本案例中我们通过模仿Mybatis手写ORM框架,通过这样操作数据库学习中介者运用场景

除了这样的中间件层使用场景外,对于一些外部接口,例如N种奖品服务,可以由中台系统进行统一包装对外提供服务能力。也是中介者模式的一种思想体现。

在本案例中我们会把jdbc层进行包装,让用户在使用数据库服务的时候,可以和使用mybatis一样简单方便,通过这样的源码方式学习中介者模式,也方便对源码知识的拓展学习,增强知识栈。

用一坨坨代码实现

这是一种关于数据库操作最初的方式

基本上每一个学习开发的人都学习过直接使用jdbc方式连接数据库,进行CRUD操作。以下的例子可以当做回忆。

1. 工程结构

itstack-demo-design-16-01
└── src
    └── main
        └── java
            └── org.itstack.demo.design
                └── JDBCUtil.java
  • 这里的类比较简单只包括了一个数据库操作类。

2. 代码实现

public class JDBCUtil {

    private static Logger logger = LoggerFactory.getLogger(JDBCUtil.class);

    public static final String URL = "jdbc:mysql://127.0.0.1:3306/itstack-demo-design";
    public static final String USER = "root";
    public static final String PASSWORD = "123456";

    public static void main(String[] args) throws Exception {
        //1. 加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        //2. 获得数据库连接
        Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
        //3. 操作数据库
        Statement stmt = conn.createStatement();
        ResultSet resultSet = stmt.executeQuery("SELECT id, name, age, createTime, updateTime FROM user");
        //4. 如果有数据 resultSet.next() 返回true
        while (resultSet.next()) {
            logger.info("测试结果 姓名:{} 年龄:{}", resultSet.getString("name"),resultSet.getInt("age"));
        }
    }

}
  • 以上是使用JDBC的方式进行直接操作数据库,几乎大家都使用过这样的方式。

3. 测试结果

15:38:10.919 [main] INFO  org.itstack.demo.design.JDBCUtil - 测试结果 姓名:水水 年龄:18
15:38:10.922 [main] INFO  org.itstack.demo.design.JDBCUtil - 测试结果 姓名:豆豆 年龄:18
15:38:10.922 [main] INFO  org.itstack.demo.design.JDBCUtil - 测试结果 姓名:花花 年龄:19

Process finished with exit code 0
  • 从测试结果可以看到这里已经查询到了数据库中的数据。只不过如果在全部的业务开发中都这样实现,会非常的麻烦。

中介模式开发ORM框架

`接下来就使用中介模式的思想完成模仿Mybatis的ORM框架开发~

1. 工程结构

itstack-demo-design-16-02
└── src
    ├── main
    │   ├── java
    │   │   └── org.itstack.demo.design
    │   │       ├── dao
    │   │       │	├── ISchool.java
    │   │       │	└── IUserDao.java
    │   │       ├── mediator
    │   │       │	├── Configuration.java
    │   │       │	├── DefaultSqlSession.java
    │   │       │	├── DefaultSqlSessionFactory.java
    │   │       │	├── Resources.java
    │   │       │	├── SqlSession.java
    │   │       │	├── SqlSessionFactory.java
    │   │       │	├── SqlSessionFactoryBuilder.java
    │   │       │	└── XNode.java
    │   │       └── po
    │   │         	├── School.java
    │   │         	└── User.java
    │   └── resources
    │       ├── mapper
    │       │   ├── School_Mapper.xml
    │       │   └── User_Mapper.xml
    │       └── mybatis-config-datasource.xml
    └── test
         └── java
             └── org.itstack.demo.design.test
                 └── ApiTest.java

中介者模式模型结构

中介者模式模型结构

  • 以上是对ORM框架实现的核心类,包括了;加载配置文件、对xml解析、获取数据库session、操作数据库以及结果返回。
  • 左上是对数据库的定义和处理,基本包括我们常用的方法;<T> T selectOne<T> List<T> selectList等。
  • 右侧蓝色部分是对数据库配置的开启session的工厂处理类,这里的工厂会操作DefaultSqlSession
  • 之后是红色地方的SqlSessionFactoryBuilder,这个类是对数据库操作的核心类;处理工厂、解析文件、拿到session等。

接下来我们就分别介绍各个类的功能实现过程。

2. 代码实现

2.1 定义SqlSession接口

public interface SqlSession {

    <T> T selectOne(String statement);

    <T> T selectOne(String statement, Object parameter);

    <T> List<T> selectList(String statement);

    <T> List<T> selectList(String statement, Object parameter);

    void close();
}
  • 这里定义了对数据库操作的查询接口,分为查询一个结果和查询多个结果,同时包括有参数和没有参数的方法。

2.2 SqlSession具体实现类

public class DefaultSqlSession implements SqlSession {

    private Connection connection;
    private Map<String, XNode> mapperElement;

    public DefaultSqlSession(Connection connection, Map<String, XNode> mapperElement) {
        this.connection = connection;
        this.mapperElement = mapperElement;
    }

    @Override
    public <T> T selectOne(String statement) {
        try {
            XNode xNode = mapperElement.get(statement);
            PreparedStatement preparedStatement = connection.prepareStatement(xNode.getSql());
            ResultSet resultSet = preparedStatement.executeQuery();
            List<T> objects = resultSet2Obj(resultSet, Class.forName(xNode.getResultType()));
            return objects.get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public <T> List<T> selectList(String statement) {
        XNode xNode = mapperElement.get(statement);
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(xNode.getSql());
            ResultSet resultSet = preparedStatement.executeQuery();
            return resultSet2Obj(resultSet, Class.forName(xNode.getResultType()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    // ...

    private <T> List<T> resultSet2Obj(ResultSet resultSet, Class<?> clazz) {
        List<T> list = new ArrayList<>();
        try {
            ResultSetMetaData metaData = resultSet.getMetaData();
            int columnCount = metaData.getColumnCount();
            // 每次遍历行值
            while (resultSet.next()) {
                T obj = (T) clazz.newInstance();
                for (int i = 1; i <= columnCount; i++) {
                    Object value = resultSet.getObject(i);
                    String columnName = metaData.getColumnName(i);
                    String setMethod = "set" + columnName.substring(0, 1).toUpperCase() + columnName.substring(1);
                    Method method;
                    if (value instanceof Timestamp) {
                        method = clazz.getMethod(setMethod, Date.class);
                    } else {
                        method = clazz.getMethod(setMethod, value.getClass());
                    }
                    method.invoke(obj, value);
                }
                list.add(obj);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public void close() {
        if (null == connection) return;
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
  • 这里包括了接口定义的方法实现,也就是包装了jdbc层。
  • 通过这样的包装可以让对数据库的jdbc操作隐藏起来,外部调用的时候对入参、出参都有内部进行处理。

2.3 定义SqlSessionFactory接口

public interface SqlSessionFactory {

    SqlSession openSession();

} 
  • 开启一个SqlSession, 这几乎是大家在平时的使用中都需要进行操作的内容。虽然你看不见,但是当你有数据库操作的时候都会获取每一次执行的SqlSession

2.4 SqlSessionFactory具体实现类

public class DefaultSqlSessionFactory implements SqlSessionFactory {

    private final Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }

    @Override
    public SqlSession openSession() {
        return new DefaultSqlSession(configuration.connection, configuration.mapperElement);
    }

}
  • DefaultSqlSessionFactory,是使用mybatis最常用的类,这里我们简单的实现了一个版本。
  • 虽然是简单的版本,但是包括了最基本的核心思路。当开启SqlSession时会进行返回一个DefaultSqlSession
  • 这个构造函数中向下传递了Configuration配置文件,在这个配置文件中包括;Connection connectionMap<String, String> dataSourceMap<String, XNode> mapperElement。如果有你阅读过Mybatis源码,对这个就不会陌生。

2.5 SqlSessionFactoryBuilder实现

public class SqlSessionFactoryBuilder {

    public DefaultSqlSessionFactory build(Reader reader) {
        SAXReader saxReader = new SAXReader();
        try {
            saxReader.setEntityResolver(new XMLMapperEntityResolver());
            Document document = saxReader.read(new InputSource(reader));
            Configuration configuration = parseConfiguration(document.getRootElement());
            return new DefaultSqlSessionFactory(configuration);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

    private Configuration parseConfiguration(Element root) {
        Configuration configuration = new Configuration();
        configuration.setDataSource(dataSource(root.selectNodes("//dataSource")));
        configuration.setConnection(connection(configuration.dataSource));
        configuration.setMapperElement(mapperElement(root.selectNodes("mappers")));
        return configuration;
    }

    // 获取数据源配置信息
    private Map<String, String> dataSource(List<Element> list) {
        Map<String, String> dataSource = new HashMap<>(4);
        Element element = list.get(0);
        List content = element.content();
        for (Object o : content) {
            Element e = (Element) o;
            String name = e.attributeValue("name");
            String value = e.attributeValue("value");
            dataSource.put(name, value);
        }
        return dataSource;
    }

    private Connection connection(Map<String, String> dataSource) {
        try {
            Class.forName(dataSource.get("driver"));
            return DriverManager.getConnection(dataSource.get("url"), dataSource.get("username"), dataSource.get("password"));
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    // 获取SQL语句信息
    private Map<String, XNode> mapperElement(List<Element> list) {
        Map<String, XNode> map = new HashMap<>();

        Element element = list.get(0);
        List content = element.content();
        for (Object o : content) {
            Element e = (Element) o;
            String resource = e.attributeValue("resource");

            try {
                Reader reader = Resources.getResourceAsReader(resource);
                SAXReader saxReader = new SAXReader();
                Document document = saxReader.read(new InputSource(reader));
                Element root = document.getRootElement();
                //命名空间
                String namespace = root.attributeValue("namespace");

                // SELECT
                List<Element> selectNodes = root.selectNodes("select");
                for (Element node : selectNodes) {
                    String id = node.attributeValue("id");
                    String parameterType = node.attributeValue("parameterType");
                    String resultType = node.attributeValue("resultType");
                    String sql = node.getText();

                    // ? 匹配
                    Map<Integer, String> parameter = new HashMap<>();
                    Pattern pattern = Pattern.compile("(#\\{(.*?)})");
                    Matcher matcher = pattern.matcher(sql);
                    for (int i = 1; matcher.find(); i++) {
                        String g1 = matcher.group(1);
                        String g2 = matcher.group(2);
                        parameter.put(i, g2);
                        sql = sql.replace(g1, "?");
                    }

                    XNode xNode = new XNode();
                    xNode.setNamespace(namespace);
                    xNode.setId(id);
                    xNode.setParameterType(parameterType);
                    xNode.setResultType(resultType);
                    xNode.setSql(sql);
                    xNode.setParameter(parameter);

                    map.put(namespace + "." + id, xNode);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
        return map;
    }

}
  • 在这个类中包括的核心方法有;build(构建实例化元素)parseConfiguration(解析配置)dataSource(获取数据库配置)connection(Map<String, String> dataSource) (链接数据库)mapperElement (解析sql语句)
  • 接下来我们分别介绍这样的几个核心方法。

build(构建实例化元素)

这个类主要用于创建解析xml文件的类,以及初始化SqlSession工厂类DefaultSqlSessionFactory。另外需要注意这段代码saxReader.setEntityResolver(new XMLMapperEntityResolver());,是为了保证在不联网的时候一样可以解析xml,否则会需要从互联网获取dtd文件。

parseConfiguration(解析配置)

是对xml中的元素进行获取,这里主要获取了;dataSourcemappers,而这两个配置一个是我们数据库的链接信息,另外一个是对数据库操作语句的解析。

connection(Map<String, String> dataSource) (链接数据库)

链接数据库的地方和我们常见的方式是一样的;Class.forName(dataSource.get("driver"));,但是这样包装以后外部是不需要知道具体的操作。同时当我们需要链接多套数据库的时候,也是可以在这里扩展。

mapperElement (解析sql语句)

这部分代码块内容相对来说比较长,但是核心的点就是为了解析xml中的sql语句配置。在我们平常的使用中基本都会配置一些sql语句,也有一些入参的占位符。在这里我们使用正则表达式的方式进行解析操作。

解析完成的sql语句就有了一个名称和sql的映射关系,当我们进行数据库操作的时候,这个组件就可以通过映射关系获取到对应sql语句进行操作。

3. 测试验证

在测试之前需要导入sql语句到数据库中;

  • 库名:itstack-demo-design
  • 表名:userschool
CREATE TABLE school ( id bigint NOT NULL AUTO_INCREMENT, name varchar(64), address varchar(256), createTime datetime, updateTime datetime, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into school (id, name, address, createTime, updateTime) values (1, '北京大学', '北京市海淀区颐和园路5', '2019-10-18 13:35:57', '2019-10-18 13:35:57');
insert into school (id, name, address, createTime, updateTime) values (2, '南开大学', '中国天津市南开区卫津路94', '2019-10-18 13:35:57', '2019-10-18 13:35:57');
insert into school (id, name, address, createTime, updateTime) values (3, '同济大学', '上海市彰武路1号同济大厦A77', '2019-10-18 13:35:57', '2019-10-18 13:35:57');
CREATE TABLE user ( id bigint(11) NOT NULL AUTO_INCREMENT, name varchar(32), age int(4), address varchar(128), entryTime datetime, remark varchar(64), createTime datetime, updateTime datetime, status int(4) DEFAULT '0', dateTime varchar(64), PRIMARY KEY (id), INDEX idx_name (name) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into user (id, name, age, address, entryTime, remark, createTime, updateTime, status, dateTime) values (1, '水水', 18, '吉林省榆树市黑林镇尹家村5', '2019-12-22 00:00:00', '', '2019-12-22 00:00:00', '2019-12-22 00:00:00', 0, '20200309');
insert into user (id, name, age, address, entryTime, remark, createTime, updateTime, status, dateTime) values (2, '豆豆', 18, '辽宁省大连市清河湾司马道407', '2019-12-22 00:00:00', '', '2019-12-22 00:00:00', '2019-12-22 00:00:00', 1, null);
insert into user (id, name, age, address, entryTime, remark, createTime, updateTime, status, dateTime) values (3, '花花', 19, '辽宁省大连市清河湾司马道407', '2019-12-22 00:00:00', '', '2019-12-22 00:00:00', '2019-12-22 00:00:00', 0, '20200310');

3.1 创建数据库对象类

用户类

public class User {

    private Long id;
    private String name;
    private Integer age;
    private Date createTime;
    private Date updateTime;
    
    // ... get/set
}

学校类

public class School {

    private Long id;
    private String name;
    private String address;
    private Date createTime;
    private Date updateTime;  
  
    // ... get/set
}
  • 这两个类都非常简单,就是基本的数据库信息。

3.2 创建DAO包

用户Dao

public interface IUserDao {

     User queryUserInfoById(Long id);

}

学校Dao

public interface ISchoolDao {

    School querySchoolInfoById(Long treeId);

} 

3.3 ORM配置文件

链接配置

<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://127.0.0.1:3306/itstack_demo_design?useUnicode=true"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="mapper/User_Mapper.xml"/>
        <mapper resource="mapper/School_Mapper.xml"/>
    </mappers>

</configuration>
  • 这个配置与我们平常使用的mybatis基本是一样的,包括了数据库的连接池信息以及需要引入的mapper映射文件。

操作配置(用户)

<mapper namespace="org.itstack.demo.design.dao.IUserDao">

    <select id="queryUserInfoById" parameterType="java.lang.Long" resultType="org.itstack.demo.design.po.User">
        SELECT id, name, age, createTime, updateTime
        FROM user
        where id = #{id}
    </select>

    <select id="queryUserList" parameterType="org.itstack.demo.design.po.User" resultType="org.itstack.demo.design.po.User">
        SELECT id, name, age, createTime, updateTime
        FROM user
        where age = #{age}
    </select>

</mapper>

操作配置(学校)

<mapper namespace="org.itstack.demo.design.dao.ISchoolDao">

    <select id="querySchoolInfoById" resultType="org.itstack.demo.design.po.School">
        SELECT id, name, address, createTime, updateTime
        FROM school
        where id = #{id}
    </select>

</mapper>

3.4 单个结果查询测试

@Test
public void test_queryUserInfoById() {
    String resource = "mybatis-config-datasource.xml";
    Reader reader;
    try {
        reader = Resources.getResourceAsReader(resource);
        SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = sqlMapper.openSession();
        try {
            User user = session.selectOne("org.itstack.demo.design.dao.IUserDao.queryUserInfoById", 1L);
            logger.info("测试结果:{}", JSON.toJSONString(user));
        } finally {
            session.close();
            reader.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
  • 这里的使用方式和Mybatis是一样的,都包括了;资源加载和解析、SqlSession工厂构建、开启SqlSession以及最后执行查询操作selectOne

测试结果

16:56:51.831 [main] INFO  org.itstack.demo.design.demo.ApiTest - 测试结果:{"age":18,"createTime":1576944000000,"id":1,"name":"水水","updateTime":1576944000000}

Process finished with exit code 0
  • 从结果上看已经满足了我们的查询需求。

3.5 集合结果查询测试

@Test
public void test_queryUserList() {
    String resource = "mybatis-config-datasource.xml";
    Reader reader;
    try {
        reader = Resources.getResourceAsReader(resource);
        SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = sqlMapper.openSession();
        try {
            User req = new User();
            req.setAge(18);
            List<User> userList = session.selectList("org.itstack.demo.design.dao.IUserDao.queryUserList", req);
            logger.info("测试结果:{}", JSON.toJSONString(userList));
        } finally {
            session.close();
            reader.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
  • 这个测试内容与以上只是查询方法有所不同;session.selectList,是查询一个集合结果。

测试结果

16:58:13.963 [main] INFO  org.itstack.demo.design.demo.ApiTest - 测试结果:[{"age":18,"createTime":1576944000000,"id":1,"name":"水水","updateTime":1576944000000},{"age":18,"createTime":1576944000000,"id":2,"name":"豆豆","updateTime":1576944000000}]

Process finished with exit code 0
  • 测试验证集合的结果也是正常的,目前位置测试全部通过。

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

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

相关文章

Maven项目中出现【不再支持目标选项 1.5】的解决办法

1 快速解决【单项目】 本方法只适用于单个项目&#xff0c;新建项目使用maven还会出现问题。 在pom.xml配置&#xff1a; <properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target>&l…

高并发高吞吐IO秘密武器——epoll池化技术

1、epoll函数详解 epoll是Linux特有的IO复用函数&#xff0c;使用一组函数来完成任务&#xff0c;而不是单个函数。 epoll把用户关心的文件描述符上的事件放在内核的一个事件表中&#xff0c;不需要像select、poll那样每次调用都要重复传入文件描述符集或事件集。 epoll需要…

闲人闲谈PS之四十一——重新认识PS模块

惯例闲话&#xff1a;4月份参加了SAP咨询大师乐老师组织的公司间业务培训&#xff0c;印象极为深刻&#xff0c;乐老师从三权分立的角度同大家分析了公司间业务交易对象–库存的属地权、管理权、所有权&#xff0c;通过这种全新的视角&#xff0c;把复杂难以理解的公司交易用最…

万字复盘Vue2相关知识(适合学过但忘了然而需要上手的朋友)

目录 前言一&#xff0c;Vue2项目的创建及基本配置1.1 用脚手架创建项目1.2 项目结构1.3 入口文件main.js1.4 组件配置1.4 运行项目 二&#xff0c;Vue的基础知识2.1 数据显示2.2 数据绑定2.3 事件处理2.4 循环遍历2.5 判断语法2.6 计算属性2.7 监视属性 三&#xff0c;重要的生…

python 资料

算法和设计模式 Python实现算法和设计模式 algorithms - Python的一个算法模块. PyPattyrn - 一个用于实现常见设计模式的简单而有效的库. python-patterns - Python中设计模式的集合. sortedcontainers - 快速&#xff0c;纯Python的SortedList&#xff0c;SortedDict和So…

第1章:算法基础【AcWing】

文章目录 快速排序题目描述输入格式输出格式样例样例输入样例输出 提示 算法&#xff08;分治&#xff0c;双指针&#xff09; O ( n l o g n ) O(nlogn) O(nlogn)示例代码注意事项时间复杂度稳定性 归并排序题目描述算法&#xff08;分治&#xff0c;双指针&#xff09; O (…

数据库系统-索引

一、什么是索引 字典中的目录&#xff0c;就是生活中的索引 **索引&#xff1a;**定义在存储表基Table础之上&#xff0c;有助于无需检查所有记录而快速定位所需记录的一种辅助存储结构&#xff0c;由一些列存储在磁盘上的索引项index etries组成&#xff0c;每一个索引项又由…

诊断报文和通讯报文有什么区别?

&#x1f345; 我是蚂蚁小兵&#xff0c;专注于车载诊断领域&#xff0c;尤其擅长于对CANoe工具的使用&#x1f345; 寻找组织 &#xff0c;答疑解惑&#xff0c;摸鱼聊天&#xff0c;博客源码&#xff0c;点击加入&#x1f449;【相亲相爱一家人】&#x1f345; 玩转CANoe&…

YOLOv5+双目实现三维跟踪(python)

YOLOv5双目实现三维跟踪&#xff08;python&#xff09; 1. 目标跟踪2. 测距模块2.1 测距原理2.2 添加测距 3. 细节修改&#xff08;可忽略&#xff09;4. 实验效果 相关链接 1. YOLOV5 双目测距&#xff08;python&#xff09; 2. YOLOV7 双目测距&#xff08;python&#x…

【红队APT】钓鱼篇Office-CVE漏洞RLO隐藏压缩包释放免杀打包捆绑

文章目录 文件后缀-钓鱼伪装-RLO压缩文件-自解压-释放执行Office套件-CVE漏洞-MSF&CSMicrosoft MSDT CVE-2022-30190 代码执行Microsoft MSHTML CVE-2021-40444 远程代码执行CVE-2017-11882 文件后缀-钓鱼伪装-RLO 经过免杀后的exe程序(xgpj.exe)&#xff0c;进行重命名&a…

float,flex和grid布局

页面布局往往会影响着整体的结构与项目的样式&#xff0c;通常我们用的布局方式有三种&#xff1a;float,flex,grid 1.float或position布局 1.1概念 首先对于一个页面来说&#xff0c;有浮动流&#xff0c;文档流&#xff0c;文本流这几种模式&#xff0c;而float布局则是脱离…

接口文档设计的12个注意点

前言 我们做后端开发的,经常需要定义接口文档。 最近在做接口文档评审的时候&#xff0c;发现一个小伙伴定义的出参是个枚举值&#xff0c;但是接口文档没有给出对应具体的枚举值。其实&#xff0c;如何写好接口文档&#xff0c;真的很重要。今天给你带来接口文档设计的12个注…

Camera Tuning - MTK pipeline

MTK ISP Pipeline 模块介绍&#xff1a; BPC&#xff1a;坏点矫正 OBC&#xff1a;OB矫正 FUS&#xff1a;此节点处理后&#xff0c;支持视频、预览HDR Digital Gain&#xff1a; 1、LSC&#xff1a;shading矫正 2、WB&#xff1a;白平衡矫正&#xff08;此步处理后&#xff0…

数字设计笔试Verilog手撕代码 - 累加器

前言 本系列整理关于数字设计的笔试或面试的设计问题&#xff0c;手撕代码继续撕&#xff0c;今天撕一个百度昆仑笔试题的累加器设计。 设计需求 题目来源&#xff1a; 【数字IC/FPGA】百度昆仑芯手撕代码–累加器 已知一个加法器IP&#xff0c;其功能是计算两个数的和&am…

虚幻图文笔记:如何清理Character Creator角色的垃圾数据

书接上文《虚幻图文笔记&#xff1a;Character Creator 4角色通过AutoSetup For Unreal Engine插件导入UE5.1的过程笔记》 在一个项目中我按照上文的步骤导入UE5&#xff0c;但是产生了一些莫名其妙的文件&#xff0c;下面还原一下发现和解决问题的过程。 1. 使用Character Cr…

【C++入门必备知识】

【C入门必备知识】 ①.【命名空间】1.命名空间定义Ⅰ.正常定义命名空间Ⅱ.嵌套定义命名空间Ⅲ.合并命名空间 2.命名空间的使用Ⅰ.命名空间名称及域作用限定符Ⅱ.using成员引入Ⅲ.using namespace名称全部引入 3.注意事项Ⅰ.概念1.全缺省参数2.半缺省参数3.使用规则4.应用场景再…

Baumer工业相机堡盟工业相机如何通过BGAPISDK的软触发实现两相机的同步采集(C#)

Baumer工业相机堡盟工业相机如何通过BGAPISDK的软触发实现两相机的同步采集&#xff08;C#&#xff09; Baumer工业相机Baumer工业相机的高速同步采集的技术背景Baumer工业相机通过BGAPI SDK在回调函数里同步保存图像工业相机在回调函数BufferEvent保存工业相机使用软触发进行同…

#Chrome扩展程序开发教程--04:权限申请

#Chrome扩展程序开发教程--04&#xff1a;权限申请 引言1、基本介绍2、权限相关属性2.1、permissions2.2、optional_permissions2.3、host_permissions2.4、optional_host_permissions 3、申请权限4、检查权限5、移除权限 引言 本系列博客旨在带来最新的Chrome扩展程序开发入门…

C语言函数大全-- m 开头的函数

C语言函数大全 本篇介绍C语言函数大全-- m 开头的函数 1. malloc 1.1 函数说明 函数声明函数功能void *malloc(size_t size);用于动态分配内存 参数&#xff1a; size &#xff1a; 需要分配的内存大小&#xff08;以字节为单位&#xff09; 返回值&#xff1a; 如果分配成…

【Spring】三大依赖注入(@Autowired,Setter,构造方法)

目录 一、属性注入&#xff08;Autowired&#xff09; 1.1 优点分析 1.2 缺点分析 1.2.1 无法实现final修饰的变量注入。 1.2.2 兼容性不好 1.2.3 &#xff08;可能违背&#xff09;设计原则问题 1.2.4 代码举例&#xff1a; 1.2.5 出现循环依赖该怎么办&#xff1f; 二…