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

Spring学习(一)——Sping-XML

一、Spring的概述

(一)什么是Spring?

        Spring是针对bean对象的生命周期进行管理的轻量级容器。提供了功能强大IOC、AOP及Web MVC等功能。Spring框架主要由七部分组成:分别是 Spring Core、 Spring AOP、 Spring ORM、 Spring DAO、Spring Context、 Spring Web和 Spring Web MVC。

        官网:https://spring.io/

(二)Spring核心功能

Spring框架可以和任意框架进行整合。

  • IOC——控制反转

  • DI——依赖注入

  • AOP——面向切面

(三)Spring的好处

  • 高内聚低耦合

    • 高内聚:让方法责任更加单一,更加纯粹,最大程度的保证内聚以及责任单一

    • 低耦合:减少代码之间的关联,即一个类对另外一个类的依赖程度,极可能让类与类之间的关联降到最低

    • 原则:

      • 责任单一原则:需要用整个编程生涯来贯彻

      • 最少知道原则:禁止跨级调用;让一个类认识/调用最少的类

  • 简化事务:仅仅使用一个注解,就能让事务生效

  • 集成了Junit,方便测试

  • 简化了开发

  • 方便集成各种框架:使用Spring去管理所有的框架

二、IOC(控制反转)

(一)IOC的概念

        控制权从应用程序代码转移到外部容器,由容器负责管理对象的创建和依赖关系。

(二)创建Spring项目

添加依赖

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.1.9.RELEASE</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.30</version><scope>provided</scope></dependency></dependencies>

创建spring配置文件:spring1.xml

编辑spring.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"><!--当前的Student类交给了Spring容器去创建--><bean id="stu" class="com.javatest.demo.Student"/>
</beans>

创建Student类

@Getter
@Setter
public class Student {private Integer id;private String name;private Integer age;
}

测试类

private static void test1() {// 从类加载路径中,加载配置文件spring1.xml// 读取配置文件中的内容// 解析xml标签// 创建一个bean的集合,new一个对象,存入bean的集合等待调用// applicationContext 实际上就是Spring容器对象// 不论是否调用bean对象,在Spring容器初始化的时候,都会创建bean对象ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring1.xml");// 从Spring容器中,寻找id=stu的bean对象Student stu= (Student) applicationContext.getBean("stu");// 赋值stu.setId(100);stu.setName("张三");stu.setAge(11);System.out.println(stu);
}

运行结果:

----------Student创建了-------------
Student(id=100, name=张三, age=11)

(三)Spring的启动原理

        程序启动 → 读取xml文件 → 解析xml配置文件 → 读取了bean标签的内容 → 通过反射,初始化bean对象(new对象) → bean对象 存入Spring容器,等待调用。

代码实现:

public static void main(String[] args) throws Exception {test4();
}
private static void test4() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {Student student = (Student) test3("stu");student.setId(10);student.setName("张三");student.setAge(30);System.out.println(student);// Student(id=10, name=张三, age=30)
}
private static Object test3(String id) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {Map<String, Object> map = test2();Object o = map.get(id);return o;
}
private static Map<String, Object> test2() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {String id = "stu";String className = "com.javatest.demo.Student";Class<?> aClass = Class.forName(className);Object o = aClass.getConstructor().newInstance();Map<String, Object> springApplication = new ConcurrentHashMap<>();springApplication.put(id, o);return springApplication;
}

运行结果:

---------------Student对象被创建了---------------
Student(id=10, name=张三, age=30)

 (四)Spring中获取bean的三种方式

Studen类:

@Getter
@Setter
//@ToString
public class Student {private Integer id;private String name;private Integer age;public Student(){System.out.println("---------------Student对象被创建了---------------");}
}

spring1.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"><!--当前的Student类交给了Spring容器去创建--><bean id="stu" class="com.javasm.demo.Student"/>
</beans>

Spring获取bean的三种方式: 

public class Test2 {static ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring1.xml");public static void main(String[] args) throws Exception {test1();}/*** 获取bean的方式*/private static void test1() {// 根据id获取Student student = (Student) applicationContext.getBean("stu");System.out.println(student);// 根据类型获取Student student1 = applicationContext.getBean(Student.class);System.out.println(student1);// 根据id+类型获取Student student2 = applicationContext.getBean("stu", Student.class);System.out.println(student2);}
}

运行结果:

----------Student创建了-------------
com.javatest.demo.Student@6989da5e
com.javatest.demo.Student@6989da5e
com.javatest.demo.Student@6989da5e

(五)bean别名

<!--别名,不常用-->
<alias name="stu" alias="s"/>
Student s = context.getBean("s", Student.class);

(六)Spring创建bean的几种方式

1.无参构造(最常用)

<bean id="stu" class="com.javatest.demo.Student"/>

2.静态工厂创建bean对象

<bean id="xiaoming" class="com.javatest.demo.StudentStaticFactory" factory-method="getStudent"/>
public class StudentStaticFactory {public static Student getStudent() {Student student = new Student();student.setName("小明");return student;}
}
private static void test3() {Object xiaoming = applicationContext.getBean("xiaoming");System.out.println(xiaoming);// Student(id=null, name=小明, age=null)
}

3.实例工厂创建bean对象

<bean id="stuFactory" class="com.javatest.demo.StudentFactory"/>
<bean id="xiaohong" factory-bean="stuFactory" factory-method="getStudent"/>
public class StudentFactory {public Student getStudent() {Student student = new Student();student.setName("小红");return student;}
}
private static void test4() {Object xiaohong = applicationContext.getBean("xiaohong");System.out.println(xiaohong);// Student(id=null, name=小红, age=null)
}

4.Spring工厂创建bean对象

<bean id="huowang" class="com.javatest.demo.StudentSpringFactory"/>
public class StudentSpringFactory implements FactoryBean<Student> {@Overridepublic Student getObject() throws Exception {//返回的对象是什么,Spring容器中存什么Student student = new Student();student.setName("李火旺");return student;}@Overridepublic Class<?> getObjectType() {return Student.class;}@Overridepublic boolean isSingleton() {//是否是单例//true:单例//false:多例//默认是truereturn true;}
}
private static void test5() {Object huowang = applicationContext.getBean("huowang");System.out.println(huowang);Object huowang1 = applicationContext.getBean("huowang");System.out.println(huowang1);// com.javatest.demo.Student@489115ef// com.javatest.demo.Student@489115ef
}

(七)单例

Spring的bean对象,在默认情况下,都是单例的

<bean id="teacher" class="com.javasm.demo.Teacher" scope="prototype"/>

单例:Spring启动 → 加载解析XML文件 → 创建Bean对象 →bean保存到容器 →随着容器关闭销毁

多例:Spring启动→加载解析XML文件→先把解析的内容记录下来→调用的时候创建bean

(八)懒加载 

不使用不创建对象

仅仅对单例生效:

<bean id="teacher1" class="com.javasm.demo.Teacher" lazy-init="true"/>

全局配置:

<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"default-lazy-init="true"
>

(九)初始化&销毁

@Getter
@Setter
public class Teacher {private Integer id;private String name;public Teacher(Integer id, String name) {this.id = id;this.name = name;}public Teacher() {System.out.println("------------Teacher---------");}public void test1() {System.out.println("我是Test1-----------初始化");}public void test2() {System.out.println("我是Test2=============销毁");}
}
<bean id="teacher2" class="com.javatest.demo.Teacher" init-method="test1" destroy-method="test2"/>
private static void test7() {Object teacher2 = applicationContext.getBean("teacher2");System.out.println(teacher2);applicationContext.close();
}

执行顺序:

  • 构造方法
  • 初始化方法
  • 正常调用方法
  • ---销毁
  • 关闭容器 

三、DI(依赖注入)

(一)DI的概念 

        通过外部容器将依赖的对象传递给类,而不是让类自己创建或查找依赖,从而实现松耦合。

(二)代码实现

1.实体类

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Game {private Integer id;private String name;private Double price;//公司private Company company;//英雄列表private String[] heros;//关卡private List<String> levels;//背包private Map<Integer, String> items;//成就private Set<String> achievements;//游戏配置private Properties gameConfig;//玩家列表private List<Player> playerList;
}
@Data
public class Company {private String name;private String address;
}
@Data
public class Player {private Integer id;private String nickname;
}

2.spring2.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"><bean id="game" class="com.javatest.demo2.Game"><property name="id" value="1000"/><property name="name" value="黑神话·悟空"/><property name="price" value="648.88"/><!--公司--><property name="company" ref="company"/><!--英雄列表--><property name="heros"><array><value>孙悟空</value><value>杨戬</value><value>哪吒</value></array></property><!--关卡列表--><property name="levels"><list><value>黑风寨</value><value>黄风岭</value><value>小西天</value></list></property><!--背包列表--><property name="items"><map><entry key="1001" value="金箍棒"/><entry key="1002" value="三尖两刃刀"/><entry key="1003" value="定风珠"/></map></property><!--成就列表--><property name="achievements"><set><value>借刀杀人</value><value>顺手牵羊</value><value>万箭齐发</value></set></property><!--游戏配置列表--><property name="gameConfig"><props><prop key="maxPlayer">100</prop><prop key="maxLevel">120</prop></props></property><!--玩家列表--><property name="playerList"><list><bean class="com.javatest.demo2.Player"><property name="id" value="1001"/><property name="nickname" value="玩家1"/></bean><ref bean="player2"/></list></property></bean><bean id="company" class="com.javatest.demo2.Company"><property name="name" value="游戏科学"/><property name="address" value="杭州"/></bean><bean id="player2" class="com.javatest.demo2.Player"><property name="id" value="1002"/><property name="nickname" value="玩家2"/></bean>
</beans>

3.测试类

public class Test {static ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring2.xml");public static void main(String[] args) {test1();}private static void test1() {Game game = applicationContext.getBean("game", Game.class);System.out.println(game);}
}

4.运行结果 

Game(id=1000, name=黑神话·悟空, price=648.88, 
company=Company(name=游戏科学, address=杭州), 
heros=[孙悟空, 杨戬, 哪吒], 
levels=[黑风寨, 黄风岭, 小西天], 
items={1001=金箍棒, 1002=三尖两刃刀, 1003=定风珠}, 
achievements=[借刀杀人, 顺手牵羊, 万箭齐发], 
gameConfig={maxLevel=120, maxPlayer=100}, 
playerList=[Player(id=1001, nickname=玩家1), Player(id=1002, nickname=玩家2)])

(三)自动装配

<!--autowire 自动装配:byType 根据属性的类型,去Spring容器中寻找对应的bean对象,如果找到了,自动赋值给对应的属性-->
<bean id="g2" class="com.javatest.demo2.Game" autowire="byType"/>
<!--autowire 自动装配:byName 根据属性的名字,去寻找id和属性名一样的bean-->
<bean id="g3" class="com.javatest.demo2.Game" autowire="byName"/>

全局配置:

<?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"default-autowire="byName"
>

(四)构造方法的注入

Music类:

@Data
public class Music {private Integer id;private String name;private String time;private Company company;public Music(Integer id, String name, String time, Company company) {this.id = id;this.name = name;this.time = time;this.company = company;}
}

spring3.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"><bean id="company" class="com.javatest.demo2.Company"><property name="name" value="酷狗音乐"/><property name="address" value="北京"/></bean><!--index:构造方法第几个参数name: 构造方法的参数名称推荐使用index配置参数--><bean id="music" class="com.javatest.demo3.Music"><constructor-arg name="id" value="100" type="java.lang.Integer"/><constructor-arg index="1" value="云顶天宫"/><constructor-arg index="2" value="10mins"/><constructor-arg index="3" ref="company"/></bean>
</beans>

四、Spring中常见异常

1.bean的id写错了,没有找到名字是stu1的bean对象

2.根据类型,从Spring容器中获取bean对象,但是容器中有两个bean对象,是相同类型的,所以报错
因为要找1个bean,但是发现了2个 

<?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"><!--当前的Student类交给了Spring容器去创建--><bean id="stu" class="com.javatest.demo.Student"/><bean id="stu1" class="com.javatest.demo.Student"/>
</beans>

---------------Student对象被创建了---------------
---------------Student对象被创建了---------------
com.javatest.demo.Student@6989da5e
Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: 
No qualifying bean of type 'com.javatest.demo.Student' available: 
expected single matching bean but found 2: stu,stu1at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1144)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:411)at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:344)at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:337)at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1123)at com.javatest.demo.Test2.test1(Test2.java:29)at com.javatest.demo.Test2.main(Test2.java:18)

3.类中没有无参构造,报错
要养成一个习惯,只要写有参构造,不论是否需要无参构造,都要写一个 

12月 20, 2024 9:50:48 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teacher' defined in class path resource [spring1.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.javatest.demo.Teacher]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.javatest.demo.Teacher.<init>()
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teacher' defined in class path resource [spring1.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.javatest.demo.Teacher]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.javatest.demo.Teacher.<init>()at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1303)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)at com.javatest.demo.Test2.<clinit>(Test2.java:14)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.javatest.demo.Teacher]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.javatest.demo.Teacher.<init>()at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295)... 13 more
Caused by: java.lang.NoSuchMethodException: com.javatest.demo.Teacher.<init>()at java.base/java.lang.Class.getConstructor0(Class.java:3349)at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2553)at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)... 14 moreProcess finished with exit code 1

相关文章:

Spring学习(一)——Sping-XML

一、Spring的概述 (一)什么是Spring? Spring是针对bean对象的生命周期进行管理的轻量级容器。提供了功能强大IOC、AOP及Web MVC等功能。Spring框架主要由七部分组成&#xff1a;分别是 Spring Core、 Spring AOP、 Spring ORM、 Spring DAO、Spring Context、 Spring Web和 S…...

设计模式——桥接模式

文章目录 1. 定义2. 结构组成3. 桥接模式结构4. 示例代码5. 模式优势6. 总结 1. 定义 桥接模式&#xff08;Bridge Pattern&#xff09;属于结构型设计模式&#xff0c;它的主要目的是将抽象部分与它的实现部分分离&#xff0c;使它们都可以独立地变化。 2. 结构组成 桥接模…...

python Enum类介绍及cls关键字用法详解

文章目录 Enum 类基本用法定制枚举枚举方法枚举类方法 cls 关键字类方法工厂方法总结 在 Python中&#xff0c; Enum 类和 cls 关键字有一些特定的用法和含义。下面我将详细解释它们的用法&#xff1a; Enum 类 Enum 类是Python标准库中的一个类&#xff0c;用于创建枚举&a…...

模型的多GPU并行训练,DDP

DDP全称是DistributedDataParallel, 在torch.nn.parallel里面。 今天总结一下用DDP进行多GPU并行训练的方法&#xff0c; 内容来自build gpt2加上自己的补充。 如果你有多块GPU&#xff0c;就可以充分利用它们。 DDP会创建多个process&#xff08;进程&#xff0c;不是线程哦&…...

直流有刷电机多环控制(PID闭环死区和积分分离)

直流有刷电机多环控制 提高部分-第8讲 直流有刷电机多环控制实现(1)_哔哩哔哩_bilibili PID模型 外环的输出作为内环的输入,外环是最主要控制的效果,主要控制电机的位置。改变位置可以改变速度,改变速度是受电流控制。 实验环境 【 !】功能简介: 按下KEY1使能电机,按下…...

LabVIEW软件开发的未来趋势

LabVIEW软件开发的未来趋势可以从以下几个方面来分析&#xff1a; ​ 1. 与AI和机器学习的深度结合 趋势&#xff1a;LabVIEW正在向集成AI和机器学习方向发展&#xff0c;尤其是在数据处理、预测性维护和自动化控制领域。 原因&#xff1a;AI技术的普及使得实验和工业场景中的…...

ChatGPT之父:奥尔特曼

奥尔特曼 阿尔特曼一般指萨姆奥尔特曼,他是OpenAI的联合创始人兼首席执行官,被称为“ChatGPT之父”.以下是其具体介绍: 个人经历 1985年4月22日出生于美国芝加哥,8岁学会编程,9岁拥有电脑,对信息技术和互联网产生兴趣.高中就读于约翰巴勒斯中学,后进入斯坦福大学主修计…...

MySQL8.0后的double write有什么变化

什么是double write&#xff1f; 一部分是内存中的double write buffer &#xff0c;大小为2MB&#xff08;16k一个页&#xff0c;一共128个页&#xff09;。 第二部分是磁盘共享表空间的128个数据页&#xff0c;在对脏页进行落盘的时候&#xff0c;并不是直接进行落盘&#x…...

wsl ubuntu Unexpected error from cudaGetDeviceCount

wsl ubuntu Unexpected error from cudaGetDeviceCount 在这里插入图片描述 参考资料&#xff1a; Quad (4x) A6000 WSL2 CUDA Init Errors...

渐开线齿轮和摆线齿轮有什么区别?

摆线齿形与渐开线齿形的区别 虽然在比对这两种齿形&#xff0c;但有一个事情希望大家注意&#xff1a;渐开线齿轮只是摆线齿轮的一个特例。 &#xff08;1&#xff09;摆线齿形的压力角在啮合开始时最大&#xff0c;在齿节点减小到零&#xff0c;在啮合结束时再次增大到最大…...

状态图的理解和实践

状态图&#xff08;State Diagram&#xff09;是软件工程和系统设计中的一种重要工具&#xff0c;主要用于描述对象在其生命周期中的动态行为。通过状态图&#xff0c;我们可以清晰地看到对象所经历的状态序列、引起状态转移的事件&#xff08;event&#xff09;以及因状态转移…...

mysql(基础语法)

准备一张员工表 /*Navicat Premium Data TransferSource Server : localhost_3306Source Server Type : MySQLSource Server Version : 80037 (8.0.37)Source Host : localhost:3306Source Schema : studymysqlTarget Server Type : MySQLTar…...

openjdk17 从C++视角看 String的intern的jni方法JVM_InternString方法被gcc编译器连接

symbols-unix 文件部分内容 JVM_IHashCode JVM_InitClassName JVM_InitStackTraceElement JVM_InitStackTraceElementArray JVM_InitializeFromArchive JVM_InternString 要理解在 symbols-unix 文件中包含 JVM_InternString 方法的原因&#xff0c;我们需要从构建过程、符号…...

金融保险行业数字化创新实践:如何高效落地自主可控的企业级大数据平台

使用 TapData&#xff0c;化繁为简&#xff0c;摆脱手动搭建、维护数据管道的诸多烦扰&#xff0c;轻量替代 OGG, Kettle 等同步工具&#xff0c;以及基于 Kafka 的 ETL 解决方案&#xff0c;「CDC 流处理 数据集成」组合拳&#xff0c;加速仓内数据流转&#xff0c;帮助企业…...

一键打断线(根据相交点打断)——CAD c# 二次开发

多条相交线根据交点一键打断&#xff0c;如下图&#xff1a; 部分代码如下: finally namespace IFoxDemo; public class Class1 {[CommandMethod("ddx")]public static void Demo(){//"ifox可以了".Print();Database db HostApplicationServices.Workin…...

flask基础

from flask import Flask, requestapp Flask(__name__)# app.route(/) # def hello_world(): # put applications code here # return Hello World!app.route(/) # 路由 当用户访问特定 URL 时&#xff0c;Flask 会调用对应的视图函数来处理请求 def index():return …...

Springboot基于Web的高校志愿者服务管理系统81559

Springboot基于Web的高校志愿者服务管理系统81559 本系统&#xff08;程序**源码数据库调试部署开发环境&#xff09;带论文文档1****万字以上&#xff0c;文末可获取&#xff0c;系统界面在最后面。** 系统程序文件列表 项目功能&#xff1a; 志愿者,团队,招募机构,团队信息…...

各种网站(学习资源及其他)

欢迎围观笔者的个人博客~ 也欢迎通过RSS网址https://kangaroogao.github.io/atom.xml进行订阅~ 大学指南 上海交通大学生存手册中国科学技术大学人工智能与数据科学学院本科进阶指南USTC不完全入学指南大学生活质量指北科研论 信息搜集 AI信息搜集USTC飞跃网站计算机保研 技…...

熊军出席ACDU·中国行南京站,详解SQL管理之道

12月21日&#xff0c;2024 ACDU中国行在南京圆满收官&#xff0c;本次活动分为三个篇章——回顾历史、立足当下、展望未来&#xff0c;为线上线下与会观众呈现了一场跨越时空的技术盛宴&#xff0c;吸引了众多业内人士的关注。云和恩墨副总经理熊军出席此次活动并发表了主题演讲…...

Linux服务器pm2 运行chatgpt-on-wechat,搭建微信群ai机器人

安装 1.拉取项目 项目地址: chatgpt-on-wechat 2.安装依赖 pip3 install -r requirements.txt pip3 install -r requirements-optional.txt3、获取API信息 当前免费的有百度的文心一言&#xff0c;讯飞的个人认证提供500万token的额度。 控制台-讯飞开放平台 添加链接描述…...

独一无二,万字详谈——Linux之文件管理

Linux文件部分的学习&#xff0c;有这一篇的博客足矣! 目录 一、文件的命名规则 1、可以使用哪些字符&#xff1f; 2、文件名的长度 3、Linux文件名的大小写 4、Linux文件扩展名 二、文件管理命令 1、目录的创建/删除 &#xff08;1&#xff09;、目录的创建 ① mkdir…...

达梦数据库-读写分离集群部署

读写分离集群部署 读写分离集群由一个主库以及一个或者多个(最多可以配置 8 个)实时备库组成&#xff0c;基于实时归档实现的高性能数据库集群&#xff0c;不但提供数据保护、容灾等数据守护基本功能&#xff0c;还具有读写操作自动分离、负载均衡等特性。同时可以配置确认监视…...

C#(事件)2

一、事件的使用步骤 定义委托&#xff08;如果需要&#xff09;&#xff1a; 如果没有合适的预定义委托&#xff0c;就需要定义一个委托来匹配事件处理程序的签名。例如&#xff0c;public delegate void MyEventHandler(int value);定义了一个名为MyEventHandler的委托&…...

Linux xargs 命令使用教程

简介 xargs 是一个功能强大的 Linux 命令&#xff0c;用于从标准输入构建和执行命令。它接受一个命令的输出&#xff0c;并将其作为参数提供给另一个命令。它在处理大量输入时特别有用&#xff0c;其含义可以解释为&#xff1a;extended arguments&#xff0c;使用 xargs 允许…...

突发!!!GitLab停止为中国大陆、港澳地区提供服务,60天内需迁移账号否则将被删除

GitLab停止为中国大陆、香港和澳门地区提供服务&#xff0c;要求用户在60天内迁移账号&#xff0c;否则将被删除。这一事件即将引起广泛的关注和讨论。以下是对该事件的扩展信息&#xff1a; 1. 背景介绍&#xff1a;GitLab是一家全球知名的软件开发平台&#xff0c;提供代码托…...

Centos下的OpenSSH服务器和客户端

目录 1、在 IP地址为192.168.98.11的Linux主机上安装OpenSSH服务器&#xff1b; 2、激活OpenSSH服务&#xff0c;并设置开机启动&#xff1b; 3、在IP地址为192.168.98.33的Linux主机上安装OpenSSH客户端&#xff0c;使用客户端命令&#xff08;ssh、scp、sftp&#xff09;访…...

赋能新一代工业机器人-望获实时linux在工业机器人领域应用案例

在工业4.0蓬勃发展的当下&#xff0c;工业机器人作为制造业转型升级的中流砥柱&#xff0c;正朝着超精密、极速响应的方向全力冲刺。然而&#xff0c;为其适配理想的望获实时Linux系统&#xff0c;却犹如寻找开启宝藏之门的关键钥匙&#xff0c;成为众多企业在智能化进程中的棘…...

我的JAVA-Web基础(2)

1.JDBC 防止sql注入 2.JSP JSP的基本语法 基本语法是 <% %> Java代码 <% %> 输出变量 可以转换成${变量}的EL表达式 <%! %>定义变量 JSP的基本语法包括以下几个主要部分&#xff1a; 1. 表达式&#xff08;Expression&#xff09; 表达式用于将…...

OMG DDS 规范漫谈:分布式数据交互的演进之路

一、由来与起源脉络 OMG DDS&#xff08;Object Management Group Data Distribution Service&#xff09;的发展是计算机科学和技术进步的一个缩影&#xff0c;它反映了对高效、可靠的数据共享需求的响应。DDS 的概念萌生于20世纪90年代末&#xff0c;当时分布式计算已经从理…...

JVM系列(十二) -常用调优命令汇总

最近对 JVM 技术知识进行了重新整理&#xff0c;再次献上 JVM系列文章合集索引&#xff0c;感兴趣的小伙伴可以直接点击如下地址快速阅读。 JVM系列(一) -什么是虚拟机JVM系列(二) -类的加载过程JVM系列(三) -内存布局详解JVM系列(四) -对象的创建过程JVM系列(五) -对象的内存分…...

人的心理特征

一、心理特征 通过心理学实验揭示了人类在认知、情感、行为等方面的一些普遍规律。 1. 社会性与从众心理 实验例子&#xff1a;阿什的从众实验&#xff08;Asch Conformity Experiment&#xff09;结论&#xff1a;人类天生具有从众的倾向&#xff0c;尤其是在群体中&#x…...

Python(二)str、list、tuple、dict、set

string name abcdefprint(name[0]) #a # 切片&#xff1a;取部分数据 print(name[0:3]) # 取 下标为0,1,2的字符 abc print(name[2:]) # 取 下标为2开始到最后的字符 cdef print(name…...

【CryptoJS库AES加密】

当涉及到前端加密时&#xff0c;通常需要使用加密算法来保护用户的敏感信息。下面是一个使用Vue 2和Vue 3的前端加密方法的示例&#xff1a; Vue 2版本的前端加密方法&#xff1a; // 安装crypto-js库 // npm install crypto-js --save// 导入CryptoJS模块 import CryptoJS f…...

FSW3410 双通道差分器2:1/1:2USB 3.1高速模拟切换 替代ASW3410

FSW3410 是 mux 或演示系统配置中的高速双向 被动交换机&#xff0c;适用于USBType-C™ 应用程序&#xff0c; 支持 USB3.1Gen1 和 Gen2 的数据速率。基于控 制引 脚SEL &#xff0c;该 设备提供 在 PortA 或 PortB 到 PortCOM 之间的差分通道切换。 FSW3410 是一 种通用的模…...

【蓝桥杯——物联网设计与开发】基础模块8 - RTC

目录 一、RTC &#xff08;1&#xff09;资源介绍 &#x1f505;简介 &#x1f505;时钟与分频&#xff08;十分重要‼️&#xff09; &#xff08;2&#xff09;STM32CubeMX 软件配置 &#xff08;3&#xff09;代码编写 &#xff08;4&#xff09;实验现象 二、RTC接口…...

多摩川编码器协议

多摩川编码器是一种常用的绝对值编码器&#xff0c;其协议基于485硬件接口的标准NRZ协议&#xff0c;通讯波特率为固定的2.5Mbps。以下是多摩川编码器协议的详细说明&#xff1a; 硬件接口 多摩川编码器使用RS485接口进行通信&#xff0c;接口定义如下&#xff1a; 5V供电&…...

Redis篇--常见问题篇7--缓存一致性2(分布式事务框架Seata)

1、概述 在传统的单体应用中&#xff0c;事务管理相对简单&#xff0c;通常使用数据库的本地事务&#xff08;如MySQL的BEGIN和COMMIT&#xff09;来保证数据的一致性。然而&#xff0c;在微服务架构中&#xff0c;由于每个服务都有自己的数据库&#xff0c;跨服务的事务管理变…...

活着就好20241225

亲爱的朋友们&#xff0c;大家早上好&#xff01;&#x1f31e; 今天是25号&#xff0c;星期三&#xff0c;2024年12月的第二十五天&#xff0c;同时也是第51周的第三天&#xff0c;农历甲辰[龙]年十一月初二十一日。在这晨光熹微的美好时刻&#xff0c;愿那和煦而明媚的阳光照…...

navicat在pg数据库中设置自增

navicat在pg数据库中设置自增 问题来源&#xff1a; 在springboot的mubatisplus的插入数据操作时&#xff0c;我们设置了id为自增&#xff0c;但是由于数据库那边没有设置自增&#xff0c;导致数据id为null&#xff0c;插入失败&#xff0c;但是发现navicat设置pg数据库自增不…...

在瑞芯微RK3588平台上使用RKNN部署YOLOv8Pose模型的C++实战指南

在人工智能和计算机视觉领域,人体姿态估计是一项极具挑战性的任务,它对于理解人类行为、增强人机交互等方面具有重要意义。YOLOv8Pose作为YOLO系列中的新成员,以其高效和准确性在人体姿态估计任务中脱颖而出。本文将详细介绍如何在瑞芯微RK3588平台上,使用RKNN(Rockchip N…...

2025年PMP项目管理考试时间一览表

PMP认证是全球项目管理领域公认的权威认证&#xff0c;它不仅能证明你在项目管理方面的专业水平&#xff0c;还能大大提升你的职场竞争力&#xff01; 随着企业对项目管理人才的需求不断增长&#xff0c;获得PMP认证将为你带来更多的职业机会和高薪职位。 为了帮助大家合理安排…...

NS3学习——tcpVegas算法代码详解(1)

目录 一、源码 二、详解 1.定义日志和命名空间 2.注册Typeld类:TcpVegas和GetTypeId方法的实现 3.构造函数和析构函数 4.TcpVegas类中成员函数 (1) Fork函数 (2) PktsAcked函数 (3) EnableVegas函数 (4) DisableVegas函数 一、源码 /* -*- Mode:C; c-file-style:&qu…...

【RAII | 设计模式】C++智能指针,内存管理与设计模式

前言 nav2系列教材&#xff0c;yolov11部署,系统迁移教程我会放到年后一起更新&#xff0c;最近年末手头事情多&#xff0c;还请大家多多谅解。 上一节我们讲述了C移动语义相关的知识&#xff0c;本期我们来看看C中常用的几种智能指针&#xff0c;并看看他们在设计模式中的运…...

亚马逊云科技re:Invent:2025年将发生新变化

自从2006年推出Simple Storage Service&#xff08;S3&#xff09;和Elastic Compute Cloud&#xff08;EC2&#xff09;云计算服务以来&#xff0c;亚马逊云科技在过去的18年中&#xff0c;一直都是全球云计算技术的开创者和引领者。而随着人工智能技术的飞速发展和生成式AI时…...

某集团GIF动态验证码识别

注意,本文只提供学习的思路,严禁违反法律以及破坏信息系统等行为,本文只提供思路 如有侵犯,请联系作者下架 本文识别已同步上线至OCR识别网站: http://yxlocr.nat300.top/ocr/other/16 最近某集团更新了验证码,采用gif验证码,部分数据集展示如下...

llama.cpp:PC端测试 MobileVLM -- 电脑端部署图生文大模型

llama.cpp&#xff1a;PC端测试 MobileVLM 1.环境需要2.构建项目3.PC测试 1.环境需要 以下是经实验验证可行的环境参考&#xff0c;也可尝试其他版本。 &#xff08;1&#xff09;PC&#xff1a;Ubuntu 22.04.4 &#xff08;2&#xff09;软件环境&#xff1a;如下表所示 工…...

美国加州房价数据分析01

1.项目简介 本数据分析项目目的是分析美国加州房价数据&#xff0c;预测房价中值。 环境要求&#xff1a; ancondajupyter notebookpython3.10.10 虚拟环境&#xff1a; pandas 2.1.1 numpy 1.26.1 matplotlib 3.8.0 scikit-learn1.3.1 2. 导入并探索数据集 通用的数据分析…...

聚类算法DBSCAN 改进总结

目录 1. HDBSCAN (Hierarchical DBSCAN) 2. OPTICS (Ordering Points To Identify the Clustering Structure) 3. DBSCAN++ (DBSCAN with Preprocessing) 4. DBSCAN with k-distance 5. Density Peaks Clustering (DPC) 6. Generalized DBSCAN (GDBSCAN) 总结 是的,DBS…...

深入理解 Spring IoC 容器与依赖注入:从基本概念到高级应用的全面解析

IoC 容器与依赖注入 一、什么是IoC容器二、IoC原理1. 原理解释2. 一个通俗易懂的解释3. 举个例子a. 传统方式:手动创建对象b. IoC 和 DI:控制反转与依赖注入c. 解释d.总结三、依赖注入(DI)的三种方式1. 构造器注入(Constructor Injection)2. 字段注入(Field Injection)…...

什么是自我控制能力?如何提高自我控制能力?

什么是自我控制能力&#xff1f; 自我控制能力指&#xff0c;在遇到外在事物或者心理活动发生变化之时&#xff0c;人们仍然可以把握自身&#xff0c;指导接下来行动的能力。自我控制能力对一个人来说非常重要&#xff0c;因为在遇到一些事情之事&#xff0c;如果因为控制能力…...