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

快速学习Spring

Spring 简介

Spring 是一个开源的轻量级、非侵入式的 JavaEE 框架,它为企业级 Java 应用提供了全面的基础设施支持。Spring 的设计目标是简化企业应用的开发,并解决 Java 开发中常见的复杂性和低效率问题。

Spring常用依赖

<dependencies><!-- Spring 核心容器,包括 ApplicationContext 等 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.14</version> <!-- 替换为您需要的版本号 --></dependency><!-- Spring AOP 相关依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>5.3.14</version> <!-- 替换为您需要的版本号 --></dependency><!-- Spring 对 JDBC 的支持 --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.14</version> <!-- 替换为您需要的版本号 --></dependency><!-- Spring 对事务的支持 --><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.3.14</version> <!-- 替换为您需要的版本号 --></dependency>
</dependencies>

Spring 优点

  1. IoC 容器:Spring 的核心是一个 IoC(Inversion of Control,控制反转)容器,它负责管理应用中的组件(Bean),并通过依赖注入将它们装配在一起。这种方式降低了类之间的耦合度,使得代码更易于维护和测试。
  2. AOP 支持:Spring 提供了 AOP(Aspect-Oriented Programming,面向切面编程)的支持,可以方便地实现横切关注点的功能,如事务管理、日志记录等,从而提高代码的模块化和可重用性。
  3. 事务管理:Spring 提供了强大且灵活的事务管理支持,可以通过声明式事务或编程式事务来管理数据库事务,确保数据操作的一致性和可靠性。
  4. 数据访问:Spring 提供了对 JDBC、ORM(如 Hibernate、MyBatis)、NoSQL 数据库(如 MongoDB、Redis)等数据访问技术的集成支持,简化了数据访问层的开发。
  5. MVC 框架:Spring MVC 是一个基于前端控制器模式的 Web MVC 框架,提供了灵活的配置和强大的扩展性,帮助开发者构建响应式和可扩展的 Web 应用程序。
  6. 集成支持:Spring 提供了对各种第三方框架和技术的集成支持,如 JMS、JMX、Quartz 等,使得整合其他技术变得更加简单。
  7. 测试支持:Spring 提供了测试类和测试环境的支持,可以轻松编写单元测试、集成测试和端到端测试,帮助开发者保持代码质量和可靠性。

一、第一个Spring项目

1.1 创建项目工程

首先我们使用IDEA开发工具或Eclipse去创建一个名为 “first-spring”的maven项目。

1.2 导入依赖

在pom.xml中导入依赖

    <dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.14</version></dependency></dependencies>

1.3 编写代码 

在java包下创建一个名为pojo实体类包中创建一个 User类

public class User {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +'}';}
}

1.4 创建Spring文件

在resources包下创建spring文件,名为 application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"></beans>

1.4.1 bean标签

bean 标签就是用来创建 Java对象的。

属性有

id: 就是对象的唯一名字

class: 是对象类具体的位置

<property>: property 标签是bean中的设置属性,可以将特定的值或引用注入到bean的属性中。 

    <bean id="user" class="com.na.pojo.User"><property name="name" value="香菜的开发日记"/></bean>

以上就是通过bean去创建了一个User对象,并且为name 赋特定的值。

 1.5 运行测试

创建一个名为 MyTest的类。

public class MyTest {public static void main(String[] args) {// 获取 Spring 的上下文对象ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");// 在Spring当中去寻找对象// getBean("user") user就是我们在xml文件中 bean标签的 id属性值User user = (User) applicationContext.getBean("user");System.out.println(user.toString());}
}

二、依赖注入

在依赖注入中,不必创建对象,但必须描述如何创建它们。

通常依赖主义可以捅咕哦三种方式完成。即:

2.1 构造函数注入

2.1.1 更新User类

在User类代码中添加一个有参构造方法


public class User {private String name;public User(String name) {this.name = name;}public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +'}';}
}

2.1.2 更新application-context

编写application-context.xml 文件

2.1.3 根据下标设置

constructor-arg 构造函数标签

参数:

index 下标数值

value 具体内容值

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 根据下标参数设置值 --><bean id="user" class="com.na.pojo.User"><constructor-arg index="0" value="香菜的开发日记"/></bean></beans>
2.1.4 根据参数名设置

constructor-arg 构造函数标签

参数:

name 参数名称

value 具体内容值 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 根据参数名字设置 --><bean id="user" class="com.na.pojo.User"><constructor-arg name="name" value="香菜的开发日记"/></bean></beans>
2.1.5 根据参数类型设置

constructor-arg 构造函数标签

参数:

type 参数类型

value 具体内容值 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 根据参数类型设置 --><bean id="user" class="com.na.pojo.User"><constructor-arg type="java.lang.String" value="香菜的开发日记"/></bean></beans>
 2.1.5 运行测试
public class MyTest {public static void main(String[] args) {// 获取 Spring 的上下文对象ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");// 在Spring当中去寻找对象// getBean("user") user就是我们在xml文件中 bean标签的 id属性值User user = (User) applicationContext.getBean("user");System.out.println(user.toString());}
}

2.2 setter注入

setter注入,要求属性要有set方法。

2.2.1 编写实体类

在pojo包中创建Address实体类

public class Address {private String address;private String phone;public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public String getPhone() {return phone;}public void setPhone(String phone) {this.phone = phone;}@Overridepublic String toString() {return "Address{" +"address='" + address + '\'' +", phone='" + phone + '\'' +'}';}
}

在创建User实体类

public class User {private String name;private Address address;public User(String name) {this.name = name;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Address getAddress() {return address;}public void setAddress(Address address) {this.address = address;}@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +", address=" + address +'}';}
}

 2.2.2 为User中的name进行值注入

在application-context.xml 文件进行编写bean

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 为User实体中的name进行注入值 --><bean id="user" class="com.na.pojo.User"><property name="name" value="香菜"/></bean></beans>

 2.2.3 为User实体中的address进行注入

因为User实体中的address 是Address类型的,那就是说我们还需要创建一个Address的bean对象。 在与User的bean对象进行一个引用。

property 标签当中有一个 ref属性, ref属性就是去引用其他bean对象。

用法:

<property ref="引用bean的id值"/>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- Address实体对象 --><bean id="address" class="com.na.pojo.Address"><property name="phone" value="123456789"/><property name="address" value="黑龙江"/></bean><!-- User实体对象 --><bean id="user" class="com.na.pojo.User"><property name="name" value="小明"/><!-- 引用Address实体对象--><property name="address" ref="address"/></bean>
</beans>

2.2.4 运行测试 

public class MyTest {public static void main(String[] args) {// 获取 Spring 的上下文对象ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");User user = (User) applicationContext.getBean("user");System.out.println(user.toString());}
}

2.2.5 数组注入 

 创建一个Books实体

public class Books {private String[] books;public String[] getBooks() {return books;}public void setBooks(String[] books) {this.books = books;}@Overridepublic String toString() {return "Books{" +"books=" + Arrays.toString(books) +'}';}
}

在application-context.xml 文件中为Books创建bean对象并且注入值

array 数组注入标签

配合value标签来使用

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="books" class="com.na.pojo.Books"><property name="books"><!-- 为数组注入值 --><array><value>Java编程思想</value><value>数据结构与算法分析</value></array></property></bean>
</beans>

运行测试

public class MyArrayTest {public static void main(String[] args) {ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");Books books = (Books) applicationContext.getBean("books");System.out.println(books.toString());}
}

2.2.6 List注入

创建一个Musics实体类

public class Musics {private List<String> musics;public List<String> getMusics() {return musics;}public void setMusics(List<String> musics) {this.musics = musics;}@Overridepublic String toString() {return "Musics{" +"musics=" + musics +'}';}
}

在application-context.xml 文件中为Musics创建bean对象。

list 标签

配合value标签使用

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="musics" class="com.na.pojo.Musics"><property name="musics"><list><value>The Hardest Part</value><value>Energy</value></list></property></bean></beans>

运行测试

public class MyArrayTest {public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");Books books = (Books) applicationContext.getBean("books");System.out.println(books.toString());}
}

2.3 接口注入

在 service 包中创建一个 UserDao 和 UserService

public class UserDao {public void getUserById() {System.out.println("我是测试用户数据-1");}
}
public class UserService{private UserDao userDao;public UserService(UserDao userDao) {this.userDao = userDao;}public void setUserDao(UserDao userDao) {this.userDao = userDao;}public void getUserById(){userDao.getUserById();}
}

在application-context.xml文件中编写bean

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="com.na.service.UserDao"/><bean id="userService" class="com.na.service.UserService"><property name="userDao" ref="userDao"/></bean></beans>

运行测试

public class MyUserTest {public static void main(String[] args) {UserDao userDao = new UserDao();UserService userService = new UserService();userService.setUserDao(userDao);userService.getUserById();}
}

如何区分构造函数注入和setter注入 

构造函数注入setter注入
没有部分注入有部分注入
不会覆盖setter 属性会覆盖setter 属性
任意修改都会创建一个新实例任意修改不会创建一个新实例
使用与设置很多属性使用与设置少量属性

三、c命名空间和p命名空间

这个例子还是使用上面service中的代码

3.1 c命名空间

使用构造函数注入的方式,通过在 XML 配置文件中直接指定构造函数参数的值或引用。下面是一个示例:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:c="http://www.springframework.org/schema/c"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="com.na.service.UserDao"/><bean id="userService" class="com.na.service.UserService" c:userDao-ref="userDao"/></beans>

3.2 p命名空间 

使用属性注入的方式,通过在 XML 配置文件中指定属性的值或引用。下面是一个示例:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:c="http://www.springframework.org/schema/c"xmlns:p="http://www.springframework.org/schema/p"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="com.na.service.UserDao"/><bean id="userService" class="com.na.service.UserService" p:userDao-ref="userDao"/></beans>

四、Bean自动装配

4.1 在xml中进行配置

在 XML 配置文件中,可以使用 <bean> 标签来配置 Bean 的自动装配方式。

4.1.1 默认的自动装配方式(no):通过 autowire 属性将自动装配设置为 no,即不进行自动装配。

<bean id="userService" class="com.na.service.UserService" autowire="no"><!-- 手动配置依赖注入 -->
</bean>

4.1.2 按名称自动装配(byName)

通过 autowire 属性将自动装配设置为 byName,Spring 会根据 Bean 的名称自动匹配并进行装配。

<bean id="userDao" class="com.na.service.UserDao"/><bean id="userService" class="com.na.service.UserService" autowire="byName"><!-- userDao 将会自动注入 -->
</bean>

4.1.3 按类型自动装配(byType)

通过 autowire 属性将自动装配设置为 byName,Spring 会根据 Bean 的名称自动匹配并进行装配。

<bean id="userService" class="com.na.service.UserService" autowire="byType"><!-- userDao 将会自动注入 -->
</bean><bean id="userDaO" class="com.na.service.UserDao" />

 4.1.4 构造函数自动装配(constructor):通过 autowire 属性将自动装配设置为 constructor,Spring 会根据构造函数的参数类型自动查找并进行装配。

<bean id="userService" class="com.na.service.UserService" autowire="constructor"><!-- 构造函数参数将会自动注入 -->
</bean><bean id="userDaO" class="com.na.service.UserDao" />

4.2 在java中进行配置

4.3 隐示进行bean配置

未完待续

相关文章:

快速学习Spring

Spring 简介 Spring 是一个开源的轻量级、非侵入式的 JavaEE 框架&#xff0c;它为企业级 Java 应用提供了全面的基础设施支持。Spring 的设计目标是简化企业应用的开发&#xff0c;并解决 Java 开发中常见的复杂性和低效率问题。 Spring常用依赖 <dependencies><!-…...

c语言操作符(上)

目录 ​编辑 原码、反码、补码 1、正数 2、负数 3、二进制计算1-1 移位操作符 1、<<左移操作符 2、>>右移操作符 位操作符&、|、^、~ 1、&按位与 2、|按位或 3、^按位异或 特点 4、~按位取反 原码、反码、补码 1、正数 原码 反码 补码相同…...

vue3 可视化大屏自适应屏幕组件

首先定义了一个名叫ScreenContainerOptions的组件&#xff0c;需要传的参数如下 export type ScreenContainerOptions {width?: string | numberheight?: string | numberscreenFit?: boolean // 是否开启屏幕自适应&#xff0c;不然会按比例显示 } 组件的主要代码如下 …...

SpringCloud入门概述

1. 介绍 Spring Cloud 1.1 什么是 Spring Cloud Spring Cloud 是一个基于 Spring Boot 的微服务架构开发工具集&#xff0c;它为开发者提供了一系列开箱即用的工具和库&#xff0c;用于构建分布式系统中的微服务架构。Spring Cloud 提供了诸如服务发现、配置中心、负载均衡、…...

刷题计划_冲绿名

现在 rating 是 1104 准备刷 100道 1200的题&#xff0c;把实力提升到 1200 &#xff0c;上一个绿名 每一个分数段的题都写一百道&#xff0c;争取早日上蓝 现在 虽然 cf 里面显示写了一些这个分数段的题&#xff0c;但是自己训练的时候&#xff0c;其实是没有训练一道这个分…...

【微信小程序开发】小程序版的防抖节流应该怎么写

由于微信小程序与普通网页的开发、编译、运行机制都有所不同&#xff0c;在防抖节流的方法使用上也就需要我们做一些比较棘手的适配操作。常见的H5开发的防抖节流此处就不再分享了&#xff0c;网上有太多的教程&#xff0c;或者直接问那群AI即可。 OK&#xff0c;言归正传&…...

单片机学习笔记---蜂鸣器播放提示音音乐(天空之城)

目录 蜂鸣器播放提示音 蜂鸣器播放音乐&#xff08;天空之城&#xff09; 准备工作 主程序 中断函数 上一节讲了蜂鸣器驱动原理和乐理基础知识&#xff0c;这一节开始代码演示&#xff01; 蜂鸣器播放提示音 先创建工程&#xff1a;蜂鸣器播放提示音 把我们之前模块化的…...

软件实例分享,茶楼收银软件管理系统,支持计时计费商品销售会员管理定时语音提醒功能

软件实例分享&#xff0c;茶楼收银软件管理系统&#xff0c;支持计时计费商品销售会员管理定时语音提醒功能 一、前言 以下软件教程以 佳易王茶社计时计费管理系统软件V18.0为例说明 软件文件下载可以点击最下方官网卡片——软件下载——试用版软件下载 问&#xff1a;这个软…...

clang前端

Clang可以处理C、C和Objective-C源代码 Clang简介 Clang可能指三种不同的实体&#xff1a; 前端&#xff08;在Clang库中实现&#xff09;编译驱动程序&#xff08;在clang命令和Clang驱动程序库中实现&#xff09;实际的编译器&#xff08;在clang-ccl命令中实现&#xff0…...

ARM:AI 的翅膀,还能飞多久?

ARM&#xff08;ARM.O&#xff09;于北京时间 2024 年 2 月 8 日上午的美股盘后发布了 2024 年第三财年报告&#xff08;截止 2023 年 12 月&#xff09;&#xff0c;要点如下&#xff1a; 1、整体业绩&#xff1a;收入再创新高。ARM 在 2024 财年第三季度&#xff08;即 23Q4…...

【C语言】常见字符串函数的功能与模拟实现

目录 1.strlen() 模拟实现strlen() 2.strcpy() 模拟实现strcpy() 3.strcat() 模拟实现strcat() 4.strcmp() 模拟实现strcmp() 5.strncpy() 模拟实现strncpy() 6.strncat() 模拟实现strncat() 7.strncmp() 模拟实现strncmp() 8.strstr() 模拟实现strstr() 9.str…...

pyGMT初步使用

文章目录 安装显示地图保存地图 安装 GMT&#xff0c;即Generic Mapping Tools&#xff0c;通用制图工具&#xff0c;是GIS领域应用最广泛的制图软件之一&#xff0c;用于绘制地图、图形以及进行地球科学数据分析和可视化。而pyGMT即其为python提供的函数接口&#xff0c;故而…...

神经网络 | CNN 与 RNN——深度学习主力军

Hi&#xff0c;大家好&#xff0c;我是半亩花海。本文主要将卷积神经网络&#xff08;CNN&#xff09;和循环神经网络&#xff08;RNN&#xff09;这两个深度学习主力军进行对比。我们知道&#xff0c;从应用方面上来看&#xff0c;CNN 用于图像识别较多&#xff0c;而 RNN 用于…...

thinkphp6入门(20)-- 如何上传图片、文件

1. 配置文件 设置上传的路径 对应文件夹 2. 前端 <div class"card-body"><h1 class"card-title">用户头像</h1><img src"../../../uploads/{$user.avatar_photo_path}" alt"avatar" height"100"/&g…...

【Linux技术宝典】深入理解Linux基本指令:命令行新手指南

&#x1f4f7; 江池俊&#xff1a; 个人主页 &#x1f525;个人专栏&#xff1a; ✅数据结构冒险记 ✅Linux技术宝典 &#x1f305; 有航道的人&#xff0c;再渺小也不会迷途。 文章目录 一、Linux下基本指令1. ls 指令2. pwd指令3. clear指令4. cd指令什么是家目录&#xf…...

C++:Level1阶段测试

总结。 只要你看过我的文章&#xff0c;哪怕只是一半&#xff0c;一定能够过关&#xff01; 准备好开始测试氻吗&#xff1f; 选择题&#xff0c;每题4分&#xff0c;共40分 1、 DevC的项目创建按钮是_____ A、文件[F]” → “新建[N]” → “项目[P]... B、工具[T]” → …...

autojs自动化刷视频脚本

视频展示 视频 //悬浮窗 // var window floaty.rawWindow( // <frame gravity"center" bg"#ff00ff"> // <button id"action" w"300dp" h"300dp"> // 按钮 // </button> // </fram…...

鲁南制药“健康幸福中国年”主题航班,开启探寻健康与幸福的旅程

“小年&#xff0c;小年&#xff0c;过了今天就是年。”提到过年&#xff0c;北方人的“过年”是从腊月二十三的“小年”开始的&#xff0c;而南方地区是在明天。虽然时间不同&#xff0c;但是浓浓的年味是一样的&#xff0c;红彤彤是主色调&#xff0c;喜洋洋是主乐曲&#xf…...

CISA知识点

审计流程21%&#xff1b;运营和业务恢复23%&#xff1b;保护资产27%&#xff1b;IT治理17%&#xff1b;开发12%。 领域1-信息系统审计流程 规划-现场工作-报告 &#xff08;1&#xff09;审计规划 了解业务使命、目标、目的和流程 找到相关规定 实施风险分析&#xff08;…...

C语言求解猴子分桃子

问题&#xff1a;海滩上有一堆桃子&#xff0c;五只猴子来分。第一只猴子把这堆桃子平均分为五份&#xff0c;多了一个&#xff0c;这只 猴子把多的一个扔入海中&#xff0c;拿走了一份。第二只猴子把剩下的桃子又平均分成五份&#xff0c;又多了 一个&#xff0c;它同样把多的…...

在鸿蒙HarmonyOS 5中实现抖音风格的点赞功能

下面我将详细介绍如何使用HarmonyOS SDK在HarmonyOS 5中实现类似抖音的点赞功能&#xff0c;包括动画效果、数据同步和交互优化。 1. 基础点赞功能实现 1.1 创建数据模型 // VideoModel.ets export class VideoModel {id: string "";title: string ""…...

中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试

作者&#xff1a;Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位&#xff1a;中南大学地球科学与信息物理学院论文标题&#xff1a;BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接&#xff1a;https://arxiv.…...

优选算法第十二讲:队列 + 宽搜 优先级队列

优选算法第十二讲&#xff1a;队列 宽搜 && 优先级队列 1.N叉树的层序遍历2.二叉树的锯齿型层序遍历3.二叉树最大宽度4.在每个树行中找最大值5.优先级队列 -- 最后一块石头的重量6.数据流中的第K大元素7.前K个高频单词8.数据流的中位数 1.N叉树的层序遍历 2.二叉树的锯…...

学校时钟系统,标准考场时钟系统,AI亮相2025高考,赛思时钟系统为教育公平筑起“精准防线”

2025年#高考 将在近日拉开帷幕&#xff0c;#AI 监考一度冲上热搜。当AI深度融入高考&#xff0c;#时间同步 不再是辅助功能&#xff0c;而是决定AI监考系统成败的“生命线”。 AI亮相2025高考&#xff0c;40种异常行为0.5秒精准识别 2025年高考即将拉开帷幕&#xff0c;江西、…...

云原生玩法三问:构建自定义开发环境

云原生玩法三问&#xff1a;构建自定义开发环境 引言 临时运维一个古董项目&#xff0c;无文档&#xff0c;无环境&#xff0c;无交接人&#xff0c;俗称三无。 运行设备的环境老&#xff0c;本地环境版本高&#xff0c;ssh不过去。正好最近对 腾讯出品的云原生 cnb 感兴趣&…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...

莫兰迪高级灰总结计划简约商务通用PPT模版

莫兰迪高级灰总结计划简约商务通用PPT模版&#xff0c;莫兰迪调色板清新简约工作汇报PPT模版&#xff0c;莫兰迪时尚风极简设计PPT模版&#xff0c;大学生毕业论文答辩PPT模版&#xff0c;莫兰迪配色总结计划简约商务通用PPT模版&#xff0c;莫兰迪商务汇报PPT模版&#xff0c;…...

scikit-learn机器学习

# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可: # Also add the following code, # so that every time the environment (kernel) starts, # just run the following code: import sys sys.path.append(/home/aistudio/external-libraries)机…...

Monorepo架构: Nx Cloud 扩展能力与缓存加速

借助 Nx Cloud 实现项目协同与加速构建 1 &#xff09; 缓存工作原理分析 在了解了本地缓存和远程缓存之后&#xff0c;我们来探究缓存是如何工作的。以计算文件的哈希串为例&#xff0c;若后续运行任务时文件哈希串未变&#xff0c;系统会直接使用对应的输出和制品文件。 2 …...

32单片机——基本定时器

STM32F103有众多的定时器&#xff0c;其中包括2个基本定时器&#xff08;TIM6和TIM7&#xff09;、4个通用定时器&#xff08;TIM2~TIM5&#xff09;、2个高级控制定时器&#xff08;TIM1和TIM8&#xff09;&#xff0c;这些定时器彼此完全独立&#xff0c;不共享任何资源 1、定…...