Spring学习笔记---下篇

news2024/10/5 14:17:53

文章目录

  • Spring下篇
  • 1、代理模式
    • 1.1、静态代理
    • 1.2、加深理解
    • 1.3、动态代理
  • 2、AOP
    • 2.1、什么是AOP
    • 2.2 、Aop在Spring中的作用
    • 2.3、在Spring中使用Aop
  • 3、整合MyBatis
    • 3.1、[mybatis-spring介绍](https://mybatis.org/spring/zh/getting-started.html)
    • 3.2、整合步骤
  • 4、事务
      • 4.1、事务的四个特性(ACID)
      • 4.2、Spring中的事务管理

Spring下篇

1、代理模式

为什么要学习代理模式?(因为这就是Spring中的AOP底层)
代理模式的分类:

  • 静态代理
  • 动态代理

在这里插入图片描述

1.1、静态代理

角色分析:

  • 抽象角色:一般会使用接口或者抽象类
  • 真实角色:被代理的对象
  • 代理角色:代理真实角色,代理真实角色后,我们一般会做一些附属操作
  • 客户:访问代理的对象的人

代码步骤:

  1. 接口
//租房
public interface Rent {
    public void rent();
}
  1. 真实角色
//房东
public class Host implements Rent {
    @Override
    public void rent() {
        System.out.println("房东出租房子");
    }
}
  1. 代理角色

public class Proxy implements Rent{

    private Host host;

    public Proxy() {
    }

    public Proxy(Host host) {
        this.host = host;
    }

    @Override
    public void rent() {
        look();
        host.rent();
        heTong();
        shouFei();
    }
    //看房
    public void look(){
        System.out.println("看房!");
    }
    public void heTong(){
        System.out.println("签合同!");
    }
    public void shouFei(){
        System.out.println("中介收取中介费!");
    }
}
  1. 客户端访问代理角色
public class Client {
    public static void main(String[] args) {
        //房东要租房子
        Host host=new Host();
        //代理,中介帮房东租房子,但是代理角色一般会有一些附属操作!
        Proxy proxy=new Proxy(host);
        //不用面对房东租房子,直接找中介就好
        proxy.rent();
    }
}

代理模式的优点:

  • 可以使真实角色的操更加纯粹!不用关注一些公关业务
  • 公共也就交给了代理角色!实现了业务的分工
  • 公共业务发生拓展的时候,方便集中管理!

缺点:

  • 一个真实角色就会产生一个代理角色;代码会翻倍-开发效率会降低(动态代理-反射)

1.2、加深理解

代码:

  1. 接口
public interface UserService {
    public void add();
    public void delete();
    public void update();
    public void find();
}
  1. 真实角色
public class UserServiceImpl implements UserService{
    @Override
    public void add() {
        System.out.println("增加了一个用户!");
    }

    @Override
    public void delete() {
        System.out.println("删除了一个用户");
    }

    @Override
    public void update() {

    }
    @Override
    public void find() {
    }
}
  1. 代理角色
public class UserServiceImpl implements UserService{
    @Override
    public void add() {
        System.out.println("增加了一个用户!");
    }

    @Override
    public void delete() {
        System.out.println("删除了一个用户");
    }

    @Override
    public void update() {

    }

    @Override
    public void find() {

    }
}
  1. 客户端访问代理角色
public class Client
{
    public static void main(String[] args) {
        UserServiceImpl u=new UserServiceImpl();
        UserServiceProxy userServiceProxy=new UserServiceProxy(u);

        userServiceProxy.add();
    }
}

图解:
在这里插入图片描述

1.3、动态代理

  • 动态代理和静态代理的角色是一样的
  • 动态代理的代理类是生成的,不是我们直接写好的!
  • 动态代理分为两大类:基于接口的动态代理、基于类的动态代理
    • 基于接口–JDK的动态代理
    • 基于类的动态代理–cglib
    • Java字节码–Javasist

需要了解两个类:Proxy(代理)、InvocationHandler()

动态代理的优点:

  • 可以使真实角色的操更加纯粹!不用关注一些公关业务
  • 公共也就交给了代理角色!实现了业务的分工
  • 公共业务发生拓展的时候,方便集中管理!
  • 一个动态代理类代理的是一个接口,一般就是对应额一类业务
  • 一个动态代理类可以代理多个类,只要是实现了同一个接口即可

2、AOP

2.1、什么是AOP

AOP (Aspect Oriented Programming)意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,也是Spring框架中的一个重要内容,是函数式编程的一种衍生范型。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。
在这里插入图片描述

2.2 、Aop在Spring中的作用

  • 横切关注点:跨越应用程序多个模块的方法或功能。即是,与业务逻辑无关的,但是我们需要关注的部门,就是横切关注点。如日志,安全,缓存,事务等等。
  • 切面(ASPECT):横切关注点被模块化的特殊对象。(它是一个类)
  • 通知(Advice):切面必须完成的供。(它是一个类中的方法)
  • 目标(Target):被通知的对象。
  • 代理(Proxy):向目标对象应用通知之后创建的对象。
  • 切入点(PointCut):切面通知执行的“地点”的定义。
  • 连接点(JointPoint):与切入点匹配的执行点。

2.3、在Spring中使用Aop

重点:使用Aop植入,需要导入一个依赖包!

   <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.9.5</version>
    </dependency>

方式一:使用原生Spring API接口

  • sevice层
public interface UserService {
    public void add();
    public void delete();
    public void update();
    public void find();
}

public class UserServiceImpl implements UserService{
    @Override
    public void add() {
        System.out.println("增加了一个用户!");
    }

    @Override
    public void delete() {
        System.out.println("删除了一个用户");
    }

    @Override
    public void update() {
		 System.out.println("更新了一个用户");
    }

    @Override
    public void find() {
		 System.out.println("查询了一个用户");
    }
}
  • 日志类
public class AfterLog implements AfterReturningAdvice {
    //returnValue:返回值
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("执行了"+method.getName()+"方法,返回的结果为:"+returnValue);
    }
}



public class AfterLog implements AfterReturningAdvice {
    //returnValue:返回值
    public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
        System.out.println("执行了"+method.getName()+"方法,返回的结果为:"+returnValue);
    }
}

  • springXml配置
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd"
	    >
    <!-- 注册bean-->
    <bean id="userService" class="com.yjr.service.UserServiceImpl"/>
    <bean id="log" class="com.yjr.log.Log"/>
    <bean id="afterLog" class="com.yjr.log.AfterLog"  />
    <!-- 方式一:使用原生Spring API接口   -->
    <!-- 配置Aop:需要导入aop约束-->
    <aop:config>
        <!--切入点:expression:表达式,execution(要执行的位置!*****)        -->
        <aop:pointcut id="pointcut" expression="execution(* com.yjr.service.UserServiceImpl.*(..))" />
        <!-- 执行环绕增加-->
        <aop:advisor advice-ref="log" pointcut-ref="pointcut"/>
        <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
    </aop:config>
</beans>
  • 测试
import com.yjr.service.UserService;
import com.yjr.service.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        //动态代理的是一个接口 :注意
        UserService service = (UserService) applicationContext.getBean("userService");
        service.add();
            }
}

方式二:自定义来实现Aop【主要是切面定义】–常用

package com.yjr.diy;

public class DiyPointCut {
    public void before(){
        System.out.println("-------方法执行前-------");
    }
    public void after(){
        System.out.println("-------方法执行后-------");
    }
}

springXML配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd"
	    >
    <!-- 注册bean-->
    <bean id="userService" class="com.yjr.service.UserServiceImpl"/>
    <bean id="log" class="com.yjr.log.Log"/>
    <bean id="afterLog" class="com.yjr.log.AfterLog"  />
    <!--  方式二:自定义类  -->
    <bean id="diyPointcut"  class="com.yjr.diy.DiyPointCut"/>
    <aop:config>
        <!--自定义且门面,ref要引用的类-->
        <aop:aspect ref="diyPointcut">
            <!-- 切入点-->
            <aop:pointcut id="point" expression="execution(* com.yjr.service.UserServiceImpl.*(..))" />
            <!--通知-->
            <aop:before method="before" pointcut-ref="point"/>
            <aop:after method="after" pointcut-ref="point"/>
        </aop:aspect>

    </aop:config>

</beans>

方式三:使用注解方式来实现Aop
类配置

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

//方式三:使用注解方式实现Aop
@Aspect  //标注一个切面
public class AnnotationPointCut {
    //前置通知
    @Before("execution(* com.yjr.service.UserServiceImpl.*(..))")
    public void before(){
        System.out.println("-------方法执行前-------");
    }
    //后置通知
    @After("execution(* com.yjr.service.UserServiceImpl.*(..))")

    public void after(){
        System.out.println("-------方法执行后-------");
    }
    //环绕通知--我们可以给定一个蚕食,代表我们要获取处理切入的点
    @Around("execution(* com.yjr.service.UserServiceImpl.*(..))")
    public void around(ProceedingJoinPoint point) throws Throwable {

        System.out.println("环绕前");
        //执行方法
        Object proceed = point.proceed();
        System.out.println("环绕后");
    }
}

SpringXml配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"
>
    <!-- 注册bean-->
    <bean id="userService" class="com.yjr.service.UserServiceImpl"/>
    <bean id="log" class="com.yjr.log.Log"/>
    <bean id="afterLog" class="com.yjr.log.AfterLog"  />
    <!--方式三:使用注解实现Aop-->
    <bean id="annotationPointCut" class="com.yjr.diy.AnnotationPointCut"/>
    <!--开启注解支持   JDK(默认 proxy-target-class="false") cglib (proxy-target-class="true")-->
    <aop:aspectj-autoproxy />
  </beans>

3、整合MyBatis

3.1、mybatis-spring介绍

  1. 依赖
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>3.0.2</version>
</dependency>
  1. 快速使用
    • 编写数据源
    • SqlSessionfactorry
    • SqlSessionTemplate
    • 需要给接口添加实现类
    • 将自己写的实现类,注入到Spring中
    • 测试

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
	https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--DataSource:使用Spring的数据源替换mybatis的配置 c3p0 dbcp druid-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSl=true&amp;useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=UTC"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
    </bean>
    <!--SQLSessionFactory-->
    <bean  id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource"  ref="dataSource"/>
        <!-- 绑定mybatis的配置文件-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <property name="mapperLocations" value="classpath:com/yjr/mapper/UserMapper.xml"/>
    </bean>
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <!-- SqlSessionTemplate只能使用构造器进行注入,因为它没有set方法,只有一个构造函数-->
        <constructor-arg index="0"  ref="sqlSessionFactory"/>
    </bean>

  <!--SqlSessionTemplate方式实现整合-->
  <bean id="userMapper" class="com.yjr.mapper.UserMapperImpl2">
    <property name="sqlSession" ref="sqlSession"/>
  </bean>
  <!--  SqlSessionDaoSupport方式实现整合-->
  <bean id="userMapper2" class="com.yjr.mapper.UserMapperImpl">
    <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
  </bean>

</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-config.dtd">
<!--核心配置文件-->
<configuration>
    <!--    spring管理数据源不需再mybatis中配置数据源-->
    <typeAliases>
       <package name="com.yjr.pojo"/>
   </typeAliases>

</configuration>

UserMapperImpl:采用SqlSessionDaoSupport 完成整合(方便)

public class UserMapperImpl  extends SqlSessionDaoSupport implements UserMapper{
    public List<User> getAllUsers() {
        return getSqlSession().getMapper(UserMapper.class).getAllUsers();
    }
}

UserMapperImpl2:采用SqlSessionTemplate 方式完成整合

public class UserMapperImpl2 implements UserMapper{
        private SqlSessionTemplate sqlSession;

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }
    public List<User> getAllUsers() {
        return sqlSession.getMapper(UserMapper.class).getAllUsers();
    }
}

3.2、整合步骤

  1. 导入相关依赖
    • junit
    • mybatis
    • mysql
    • spring相关的
    • aop
    • mybatis-spring[新]
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.31</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.25</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.6</version>
        </dependency>
    </dependencies>
  1. 编写配置文件(上述Spring配置文件)

  2. 测试

    @Test
    public void getAllUsers() throws IOException {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserMapper userMapper = (UserMapper) applicationContext.getBean("userMapper2");
        System.out.println(userMapper.getAllUsers());

    }

4、事务

4.1、事务的四个特性(ACID)

  • 原子性:事务中所有操作是不可再分割的原子单位。事务中所有操作要么全部执行成功,要么全部执行失败。一个事务内的操作要么全部成功要么全部失败。

  • 一致性:事务执行后数据库状态与其它业务规则保持一致。其他特性都是为了给一致性服务的。例如买东西,张三买李四的东西,买卖前和买卖后张三和李四的所有钱数之和是保持不变的。

  • 隔离性:事务和事务之间是隔离开的,一个事务看不到另一个事务正在操作的数据。

  • 持久性:一旦事务提交成功,事务中所有的数据操作都必须被持久化到数据库中,即使提交事务后,数据库马上崩溃,在数据库重启时也必须能保证通过某种机制将数据恢复到提交后的状态。

4.2、Spring中的事务管理

  • 声明式事务:Aop
  • 编程式事务:需要在代码中,进行事务的管理

为什么需要事务?

  • 如果不配置事务,可能存在数据提交不一致的情况;
  • 如果不手动在spring中配置声明式事务,就需要在代码中手动配置事务!
  • 事务在项目的开发中十分重要,涉及到数据库的完整性和一致性的问题,非常重要!
    在Spring配置文件中配置事务:
<!--    配置声明式事务-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <constructor-arg ref="dataSource" />
    </bean>
    
    <!--结合Aop实现事务的织入-->
    <!--配置事务通知-->
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--给那些方法配置事务-->
        <!--配置事务的传播特性:new propagation-->
        <tx:attributes>
            <tx:method name="query" read-only="true"/>
            <tx:method name="add" propagation="REQUIRED"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>

<!--    配事务切入-->
    <aop:config>
        <aop:pointcut id="txPointCut" expression="execution(* com.yjr.mapper..*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
     </aop:config>

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

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

相关文章

Linux基础工具|文本编辑器Vim的使用

0.前言 您好这里是limou3434的个人博客&#xff0c;感兴趣可以看看我的其他内容。 本次我给您带来的是Linux下Vim文本编辑器的使用&#xff0c;关于vim&#xff0c;您只需要知道一些常用的指令和操作即可&#xff0c;快速上手的秘诀是实践&#xff0c;并且是多次实践。 1.Vi…

12 MFC常用控件(一)

文章目录 button 按钮设置默认按钮按下回车后会响应禁用开启禁用设置隐藏设置显示设置图片设置Icon设置光标 Cbutton 类创建按钮创建消息单选按钮多选按钮 编辑框组合框下拉框操作 CListBox插入数据获取当前选中 CListCtrl插入数据设置表头修改删除 button 按钮 设置默认按钮按…

将 YAPF 设置为默认的 Python 代码格式化工具 (VS Code, PyCharm)

yapf 是一个 python 代码格式化工具, 和 black, autopep8, pycharm 自带的格式化功能相同用途. 使用 yapf 作为我的默认格式化工具, 出于以下考虑: 我和团队使用多种 ide, 而 pycharm 自带的格式化功能在其他 ide 上没法用. 所以我需要一个通用的格式化方案来保持代码风格的一…

Unity | HDRP高清渲染管线学习笔记:Rendering Debugger窗口

HDRP给我们提供了一套完整的可视化Debug工具&#xff0c;集成在Rendering Debugger窗口。通过顶部菜单Window→Analysis→Rendering Debugger可以打开窗口。Rendering Debugger窗口不仅仅可以在编辑模式下使用&#xff0c;也可以在真机上运行时使用。&#xff08;要在真机上运行…

数据结构--栈(Stack)的基本概念

数据结构–栈(Stack)的基本概念 线性表是具有相同数据类型的n ( n ≥ 0 n\ge0 n≥0&#xff09;个数据元素的有限序列&#xff0c;其中n为表长&#xff0c;当n 0时线性表是一个空表。若用L命名线性表&#xff0c;则其一般表示为: L ( a 1 , a 2 . . . , a i , a i 1 , . . …

JavaScript 手写代码 第七期(重写数组方法三) 用于遍历的方法

文章目录 1. 为什么要手写代码&#xff1f;2. 手写代码2.1 forEach2.1.1 基本使用2.1.2 手写实现 2.2 map2.2.1 基本使用2.2.2 手写实现 2.3 filter2.3.1 基本使用2.3.2 手写实现 2.4 every2.4.1 基本使用2.4.2 手写实现 2.5 some2.5.1 基本使用2.5.2 手写实现 2.6 reduce2.6.1…

大学实训报告范文6篇

大学实训报告范文篇一&#xff1a;js实训报告 一、简介&#xff1a; Web标准并不是一个单一的标准&#xff0c;而是一个系列的标准的集合。Web标准中具有代表性的几种语言有&#xff1a;_ML可扩展标记语言、_HTML可扩展超文本标记语言、CSS层叠样式表、DOM文档对象模型、Java…

助你丝滑过度到 Vue3 常用的组合式API ②④

作者 : SYFStrive 博客首页 : HomePage &#x1f4dc;&#xff1a; VUE3~TS &#x1f4cc;&#xff1a;个人社区&#xff08;欢迎大佬们加入&#xff09; &#x1f449;&#xff1a;社区链接&#x1f517; &#x1f4cc;&#xff1a;觉得文章不错可以点点关注 &#x1f449;…

HOT25-环形链表

leetcode原题链接&#xff1a;环形链表 题目描述 给你一个链表的头节点 head &#xff0c;判断链表中是否有环。 如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测系统内部使用整数…

数据库分库分表(上)

数据库分库分表 1&#xff0c;概念 分库分表是一种数据库架构设计的方法&#xff0c;用于解决大规模数据存储和查询的性能问题。它将一个大型数据库拆分成多个小型数据库&#xff0c;每个数据库负责存储一部分数据&#xff0c;从而提高数据的读写效率和并发处理能力。 分库分…

MySQL数据库基础 17

第十七章 触发器 1. 触发器概述2. 触发器的创建2.1 创建触发器语法2.2 代码举例 3. 查看、删除触发器3.1 查看触发器3.2 删除触发器 4. 触发器的优缺点4.1 优点4.2 缺点4.3 注意点 在实际开发中&#xff0c;我们经常会遇到这样的情况&#xff1a;有 2 个或者多个相互关联的表&a…

虚幻引擎(UE5)-大世界分区WorldPartition教程(三)

文章目录 前言LevelInstance的使用1.ALevelInstance2.选择Actor创建关卡3.运行时加载LevelInstance 总结 上一篇&#xff1a;虚幻引擎(UE5)-大世界分区WorldPartition教程(二) 前言 在制作大关卡时&#xff0c;可能会遇到这样一种情况&#xff0c;就是关卡中的某些Actor会重复…

【每日一题】——Majority

&#x1f30f;博客主页&#xff1a;PH_modest的博客主页 &#x1f6a9;当前专栏&#xff1a;每日一题 &#x1f48c;其他专栏&#xff1a; &#x1f534; 每日反刍 &#x1f7e1; C跬步积累 &#x1f7e2; C语言跬步积累 &#x1f308;座右铭&#xff1a;广积粮&#xff0c;缓称…

A*算法学习笔记

1 算法思路 1、Dijkstra算法与A*算法 &#xff08;1&#xff09;Dijkstra算法&#xff08;贪心策略 优先队列&#xff09;&#xff1a; 集合S&#xff1a;已确定的顶点集合&#xff0c;初始只含源点s。 集合T&#xff1a;尚未确定的顶点集合。 算法反复从集合T中选择当前到…

开闭架构

在《不过时的经典层架构》里&#xff0c;有朋友留言关于Manager和Engine的概念&#xff0c;虽然朋友留言把概念解释清楚了。为了避免其他人有同样的疑问&#xff0c;这里我还是再解释一下。 以上是经典的四层架构&#xff0c;在这个架构中&#xff0c;Manager和Engine(引擎)都是…

【liunx配置服务自启动】liunx系统设置net Core程序开机自启动服务 centos系统

liunx系统设置net Core程序开机自启动服务 系统版本&#xff1a;Centos7.9 我的程序部署到/www/wwwroot/AcmeBookStoreHttpApiHost.com/目录下&#xff0c; 程序名是Meowv.Blog.HttpApi.Hosting.dll 1.新建自启动配置文件 首先跳转到system目录下 cd /usr/lib/systemd/syste…

【.net core】yisha框架,实体不在同一项目下设置swagger接口及实体模型注释,授权鉴权

1.Startup.cs中ConfigureServices方法中添加&#xff1a; 授权鉴权内容 #region 授权鉴权//Bearer 的scheme定义var securityScheme new OpenApiSecurityScheme(){Description "使用JWT方案授权&#xff0c;请求时&#xff0c;在请求头部信息中加入: \"Authoriza…

分布式计算模型详解:MapReduce、数据流、P2P、RPC、Agent

前言 本文隶属于专栏《大数据理论体系》&#xff0c;该专栏为笔者原创&#xff0c;引用请注明来源&#xff0c;不足和错误之处请在评论区帮忙指出&#xff0c;谢谢&#xff01; 本专栏目录结构和参考文献请见大数据理论体系 思维导图 MapReduce MapReduce 是一种分布式计算模…

Tomcat与Undertow容器性能对比分析

&#x1f468;‍&#x1f393;作者&#xff1a;bug菌 ✏️博客&#xff1a; CSDN、 掘金、 infoQ、 51CTO等 &#x1f389;简介&#xff1a;CSDN博客专家&#xff0c;C站历届博客之星Top50&#xff0c;掘金/InfoQ/51CTO等社区优质创作者&#xff0c;全网合计8w粉&#xff0c;对…

BufferedImage将图片切成圆形

原图 修改后 方法一 //文件路径 File imageFile new File(path); public BufferedImage changeImages(File imageFile) {BufferedImage avatarImage null;try {avatarImage ImageIO.read(imageFile); avatarImage scaleByPercentage(avatarImage, avatarImage.getWidth(…