Spring-1-深入理解Spring XML中的依赖注入(DI):简化Java应用程序开发
学习目标
前两篇文章我们介绍了什么是Spring,以及Spring的一些核心概念,并且快速快发一个Spring项目,以及详细讲解IOC,今天详细介绍一些DI(依赖注入)
能够配置setter方式注入属性值
能够配置构造方式注入属性值
能够理解什么是自动装配
一、依赖注入(DI配置)
1 依赖注入方式【重点】
思考:向一个类中传递数据的方式有几种?(给类中的属性赋值)
-
setter方法
-
构造方法
思考:依赖注入描述了在容器中建立bean与bean之间依赖关系的过程,注入数据类型有哪些?
-
简单类型=八种基本数据类型+String
-
引用类型
1.1 依赖注入的两种方式
- setter注入
-
简单类型
-
引用类型(很常用)
-
- 构造器注入
-
简单类型
-
引用类型
-
2 setter方式注入
思考:setter方式注入使用什么子标签?
property标签: 调用set方法赋值
name: 成员变量名, 准确来说对应set方法名,首字母大写
value: 对简单类型的成员变量赋值
ref: 对引用类型的成员变量赋值
2.1简单类型setter注入
格式:
<!-- property标签: 调用set方法赋值name: 成员变量名, 准确来说对应set方法名,首字母大写value: 对简单类型的成员变量赋值 -->
<property name="age" value="20"></property>
2.2 引用类型setter注入
格式:
<!--property标签: 调用set方法赋值name: 成员变量名, 准确来说对应set方法名,首字母大写ref: 对引用类型的成员变量赋值, 引用的对象 -->
<property name="studentDao" ref="studentDao">
</property>
2.3 setter注入代码实现
【第0步】创建项目
【第1步】导入Spring坐标
【第2步】导入Student实体类
【第3步】定义Spring管理的类(接口)
【第4步】创建Spring配置文件在resources目录下创建`application.xml`,配置setter的简单类型
【第5步】在test目录下创建`StudentServiceTest`,进行测试
【第6步】在`application.xml`,配置对应引用类型注入
【第7步】测试
【第0步】创建项目
【第1步】导入Spring坐标
<dependencies><!--导入spring的坐标spring-context,对应版本是5.2.10.RELEASE--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.15</version></dependency><!-- 导入junit的测试包 --><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.8.2</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.28</version></dependency></dependencies>
【第2步】导入Student实体类
@Data
@ToString
@AllArgsConstructor
public class Student {private String name;private String address;private Integer age;private Integer status;
}
【第3步】定义Spring管理的类(接口)
-
StudentDao接口和StudentDaoImpl实现类用于简单类型注入
package com.zbbmeta.dao;public interface StudentDao {/*** 添加学生*/void save();
}
public class StudentDaoImpl implements StudentDao {//简单类型属性private Integer age;public void setAge(Integer age) {this.age = age;}@Overridepublic void save() {System.out.println("DAO: 年龄:"+this.age);System.out.println("DAO: 添加学生信息到数据库...");}
}
-
StudentService接口和StudentServiceImpl实现类用于引用类型注入
package com.zbbmeta.service;public interface StudentService {/*** 添加学生*/void save();
}
package com.zbbmeta.service.impl;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;public class StudentServiceImpl implements StudentService {//创建成员对象private StudentDao studentDao ;//提供依赖对象对应的setter方法public void setStudentDao(StudentDao studentDao) {this.studentDao = studentDao;}@Overridepublic void save() {System.out.println("Service: 添加学生信息到数据库...");studentDao.save();}
}
【第4步】创建Spring配置文件在resources目录下创建application.xml
,配置setter的简单类型
-
定义application.xml文件中创建StudentDao类到IOC容器,并实现简单类型注入
<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 目标:setter简单类型注入--><bean class="com.zbbmeta.dao.impl.StudentDaoImpl" id="studentDao">
<!-- property标签: 调用set方法赋值name: 成员变量名, 准确来说对应set方法名,首字母大写value: 对简单类型的成员变量赋值 --><property name="age" value="20"></property></bean>
</beans>
【第5步】在test目录下创建StudentServiceTest
,进行测试
package com.zbbmeta;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class StudentServiceTest {//目标:测试setter的简单类型的注入@Testpublic void test1(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="bookService"对象StudentDao studentDao = (StudentDao) ac.getBean("studentDao");//3.执行对象方法studentDao.save();//4.关闭容器ac.close();}
-
控制台结果:
【第6步】在application.xml
,配置引用类型注入
<!-- 目标:setter引用类型注入--><bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService"><!--property标签: 调用set方法赋值name: 成员变量名, 准确来说对应set方法名,首字母大写ref: 对引用类型的成员变量赋值, 引用的对象 --><property name="studentDao" ref="studentDao"></property></bean>
【第7步】测试
//目标:测试setter的引用类型的注入@Testpublic void test2(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="bookService"对象StudentService studentService = (StudentService) ac.getBean("studentService");//3.执行对象方法studentService.save();//4.关闭容器ac.close();}
-
控制台结果
3 构造器方式注入
思考:构造方式注入使用什么子标签?
3.1 构造器注入简单类型
格式:配置中使用constructor-arg标签value属性注入简单类型
<!--constructor-arg标签: 调用构造函数方法赋值name: 成员变量名, 准确来说对应构造方法中参数名称value: 简单类型,方法参数对应的值-->
<constructor-arg name="age" value="30"></constructor-arg>
2.2 构造器注入引用类型
格式:配置中使用constructor-arg标签ref属性注入引用类型
<!--constructor-arg标签: 调用构造函数方法赋值name: 成员变量名, 准确来说对应构造方法中参数名称ref: 引用类型,属性注入引用类型对象-->
<constructor-arg name="studentDao" ref="studentDao"></constructor-arg>
3.3 构造器注入代码实现
【第0步】创建`11_2_DI_Construce`项目结构
【第1步】导入依赖坐标
【第2步】导入Student实体类
【第3步】定义Spring管理的类(接口)
【第4步】创建Spring配置文件在resources目录下创建`application.xml`,配置构造器注入简单类型
【第5步】在test目录下创建`StudentServiceTest`,进行测试
【第6步】在`application.xml`,配置构造器注入引用类型
【第7步】测试
【第0步】创建11_2_DI_Construce
项目结构
【第1步】导入依赖坐标
和之前项目依赖一致
【第2步】导入Student实体类
和之前一致
【第3步】定义Spring管理的类(接口)
-
StudentDao接口和StudentDaoImpl实现类实现构造器注入简单类型
package com.zbbmeta.dao;public interface StudentDao {/*** 添加学生*/void save();
}
package com.zbbmeta.dao.impl;import com.zbbmeta.dao.StudentDao;public class StudentDaoImpl implements StudentDao {//简单类型属性private Integer age;public StudentDaoImpl(Integer age){System.out.println("DAO: 注入简单类型 age");this.age =age;}@Overridepublic void save() {System.out.println("DAO: 年龄:"+this.age);System.out.println("DAO: 添加学生信息到数据库...");}
}
-
StudentService接口和StudentServiceImpl实现类实现构造器注入引用类型
package com.zbbmeta.service;public interface StudentService {/*** 添加学生*/void save();
}
package com.zbbmeta.service.impl;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;public class StudentServiceImpl implements StudentService {//创建成员对象private StudentDao studentDao ;public StudentServiceImpl(StudentDao studentDao){System.out.println("StudentService: 注入引用类型studentDao");this.studentDao =studentDao;}@Overridepublic void save() {System.out.println("Service: 添加学生信息到数据库...");studentDao.save();}
}
【第4步】创建Spring配置文件在resources目录下创建application.xml
,配置构造器注入简单类型
-
定义application.xml配置文件并配置StudentDaoImpl实现构造器注入简单类型
<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 目标:构造器依赖注入简单类型【了解】--><bean class="com.zbbmeta.dao.impl.StudentDaoImpl" id="studentDao"><!--constructor-arg标签: 调用构造函数方法赋值name: 成员变量名, 准确来说对应构造方法中参数名称value: 简单类型,方法参数对应的值--><constructor-arg name="age" value="30"></constructor-arg></bean>
</beans>
【第5步】在test目录下创建StudentServiceTest
,进行测试
package com.zbbmeta;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class StudentServiceTest {//目标:测试构造器的简单类型的注入@Testpublic void test1(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="studentDao"对象StudentDao studentDao = (StudentDao) ac.getBean("studentDao");//3.执行对象方法studentDao.save();//4.关闭容器ac.close();}
}
-
控制台结果:
**【第6步】在application.xml
,配置构造器注入引用类型 **
<!-- 目标:构造器依赖注入引用类型【了解】-->
<bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService"><!--constructor-arg标签: 调用构造函数方法赋值name: 成员变量名, 准确来说对应构造方法中参数名称ref: 引用类型,属性注入引用类型对象--><constructor-arg name="studentDao" ref="studentDao"></constructor-arg>
</bean>
【第7步】测试
//目标:测试setter的引用类型的注入@Testpublic void test2(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="bookService"对象StudentService studentService = (StudentService) ac.getBean("studentService");//3.执行对象方法studentService.save();//4.关闭容器ac.close();}
-
控制台结果
4 依赖自动装配【理解】
4.1 自动装配概念
-
IoC容器根据bean所依赖的资源在容器中自动查找并注入到bean中的过程称为自动装配
- 自动装配方式
-
按类型
-
按名称
-
按构造方法
-
autowire: 自动装配, 在容器中找对应对象,自动给成员变量赋值byType: 通过类型注入byName: 通过名字注入constructor: 通过构造器注入no: 不自动注入
4.2 自动装配类型
4.2.1 依赖类型自动装配
配置中使用bean标签autowire属性设置自动装配的类型
byType
使用按类型装配时(byType)必须保障容器中相同类型的bean唯一,推荐使用
格式:
<!--给成员变量赋值autowire: 自动装配, 在容器中找对应对象,自动给成员变量赋值byType: 通过类型注入byName: 通过名字注入constructor: 通过构造器注入no: 不自动注入
-->
<bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService" autowire="byType">
</bean>
4.2.2依赖bean容器名字自动装配
配置中使用bean标签autowire属性设置自动装配的类型
byName
使用按名称装配时(byName)必须保障容器中具有指定名称的bean,不推荐使用
<!--
autowire="byType" 根据成员属性名自动注入
-->
<bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService2" autowire="byName">
</bean>
4.2.3 依赖bean容器根据构造器自动装配注入
配置中使用bean标签autowire属性设置自动装配的类型
constructor
<!--
autowire="constructor"
据成员的所属类型去IOC容器中查找一样类型的对象进行调用构造函数进行给成员赋值
-->
<bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService3" autowire="constructor">
</bean>
4.3 依赖自动装配代码实现
【第0步】创建11_2_DI_Autowire项目
【第1步】导入依赖坐标
【第2步】导入Student实体类
【第3步】定义Spring管理的类(接口)
【第4步】创建Spring配置文件在resources目录下创建`application.xml`
【第5步】在test目录下创建`StudentServiceTest`
【第0步】创建11_2_DI_Autowire项目
【第1步】导入Spring坐标
和之前项目依赖一致
【第1步】导入依赖坐标
和之前一致
【第3步】定义Spring管理的类(接口)
-
StudentDao接口和StudentDaoImpl实现类
package com.zbbmeta.dao;public interface StudentDao {/*** 添加学生*/void save();
}
package com.zbbmeta.dao.impl;import com.zbbmeta.dao.StudentDao;public class StudentDaoImpl implements StudentDao {@Overridepublic void save() {System.out.println("DAO: 添加学生信息到数据库...");}
}
-
StudentService接口和StudentServiceImpl实现类
package com.zbbmeta.service;public interface StudentService {/*** 添加学生*/void save();
}
package com.zbbmeta.service.impl;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;public class StudentServiceImpl implements StudentService {//创建成员对象private StudentDao studentDao ;//提供依赖对象对应的setter方法public void setStudentDao(StudentDao studentDao) {this.studentDao = studentDao;}//构造函数StudentServiceImpl(){}public StudentServiceImpl(StudentDao studentDao) {System.out.println("Service 构造器方法");this.studentDao=studentDao;}@Overridepublic void save() {System.out.println("Service: 添加学生信息到数据库...");studentDao.save();}
}
【第4步】创建Spring配置文件在resources目录下创建application.xml
-
定义application.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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!--目标:自动装配(自动注入)--><bean class="com.zbbmeta.dao.impl.StudentDaoImpl" id="studentDao"></bean><!--autowire="byType" 根据类型自动注入【重点】成员属性:private StudentDao studentDao ; 根据成员的所属类型去IOC容器中查找一样类型的对象进行调用成员的setStudentDao(参数)注入数据--><bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService" autowire="byType"></bean><!--
autowire="byName" 根据成员属性名自动注入
成员属性:private StudentDao studentDao ; 根据成员的属性名字去IOC容器中查找一样名称的对象进行调用成员的setStudentDao(参数)注入数据--><bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService2" autowire="byName"></bean><!--autowire="constructor" 成员属性:private StudentDao studentDao构造函数:public StudentServiceImpl(StudentDao studentDao){this.studentDao = studentDao;}据成员的所属类型去IOC容器中查找一样类型的对象进行调用构造函数进行给成员赋值--><bean class="com.zbbmeta.service.impl.StudentServiceImpl" id="studentService3" autowire="constructor"></bean>
</beans>
**【第5步】在test目录下创建StudentServiceTest
进行测试
package com.zbbmeta;import com.zbbmeta.dao.StudentDao;
import com.zbbmeta.service.StudentService;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class StudentServiceTest {//目标:根据类型自动注入@Testpublic void test1(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="studentService"对象StudentService studentService = (StudentService) ac.getBean("studentService");//3.执行对象方法studentService.save();//4.关闭容器ac.close();}//目标:测试自动注入根据名称查找注入@Testpublic void test2(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="bookService"对象StudentService studentService = (StudentService) ac.getBean("studentService2");//3.执行对象方法studentService.save();//4.关闭容器ac.close();}//目标:测试构造器根据名称查找注入@Testpublic void test3(){//1.根据配置文件application.xml创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");//2.从IOC容器里面获取id="bookService"对象StudentService studentService = (StudentService) ac.getBean("studentService3");//3.执行对象方法studentService.save();//4.关闭容器ac.close();}
}
5 集合注入
5.1 注入数组类型数据
格式:
<!--调用setArray方法给成员array赋值-->
<property name="array"><array><!--new String("数据") 引用类型赋值--><bean class="java.lang.String" id="s"><constructor-arg value="100"></constructor-arg></bean><!--简单类型赋值--><value>200</value><value>300</value></array>
</property>
5.2 注入List类型数据
格式:
<!--调用setList方法给成员list赋值-->
<property name="list"><list><value>张三</value><value>李四</value><value>王五</value></list>
</property>
5.3 注入Set类型数据
格式:
<!--调用setSet方法给成员set赋值-->
<property name="set"><set><value>珠海</value><value>江门</value><value>惠州</value></set>
</property>
5.4 注入Map类型数据
<!--调用setMap方法给成员map赋值-->
<property name="map"><map><entry key="country" value="china"></entry><entry key="province" value="广东"></entry><entry key="city" value="广州"></entry></map>
</property>
5.5 注入Properties类型数据
<!--调用setMap方法给成员map赋值-->
<property name="properties"><props><prop key="country">china</prop><prop key="province">广东</prop><prop key="city">广州</prop></props>
</property>
说明:property标签表示setter方式注入,构造方式注入constructor-arg标签内部也可以写<array>、<list>、<set>、<map>、<props>标签
5.6 集合注入完整代码
【第0步】在11_3_DI_Autowired的entity包下创建Person类
【第1步】创建Spring配置文件在resources目录下创建`application-person.xml`
【第2步】在test目录下创建`PersonTest`
【第0步】在11_3_DI_Autowired的entity包下创建Person类
package com.zbbmeta.entity;import java.util.*;public class Person {private String[] array;private List<String> list;private Set<String> set;private Map<String,Object> map;private Properties properties;public Person() {}public Person(String[] array, List<String> list, Set<String> set, Map<String, Object> map, Properties properties) {this.array = array;this.list = list;this.set = set;this.map = map;this.properties = properties;}/*** 获取* @return array*/public String[] getArray() {return array;}/*** 设置* @param array*/public void setArray(String[] array) {this.array = array;}/*** 获取* @return list*/public List<String> getList() {return list;}/*** 设置* @param list*/public void setList(List<String> list) {this.list = list;}/*** 获取* @return set*/public Set<String> getSet() {return set;}/*** 设置* @param set*/public void setSet(Set<String> set) {this.set = set;}/*** 获取* @return map*/public Map<String, Object> getMap() {return map;}/*** 设置* @param map*/public void setMap(Map<String, Object> map) {this.map = map;}/*** 获取* @return properties*/public Properties getProperties() {return properties;}/*** 设置* @param properties*/public void setProperties(Properties properties) {this.properties = properties;}@Overridepublic String toString() {return "User{" +"array=" + Arrays.toString(array) +", list=" + list +", set=" + set +", map=" + map +", properties=" + properties +'}';}
}
【第1步】创建Spring配置文件在resources目录下创建application-person.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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!--目标:创建User对象并依赖注入赋值--><bean class="com.zbbmeta.entity.Person" id="person"><!--调用setArray方法给成员array赋值--><property name="array"><array><!--new String("数据") 引用类型赋值--><bean class="java.lang.String" id="s"><constructor-arg value="100"></constructor-arg></bean><!--简单类型赋值--><value>200</value><value>300</value></array></property><!--调用setList方法给成员list赋值--><property name="list"><list><value>张三</value><value>李四</value><value>王五</value></list></property><!--调用setSet方法给成员set赋值--><property name="set"><set><value>珠海</value><value>江门</value><value>惠州</value></set></property><!--调用setMap方法给成员map赋值--><property name="map"><map><entry key="country" value="china"></entry><entry key="province" value="广东"></entry><entry key="city" value="广州"></entry></map></property><!--调用setMap方法给成员map赋值--><property name="properties"><props><prop key="country">china</prop><prop key="province">广东</prop><prop key="city">广州</prop></props></property></bean>
</beans>
【第2步】在test目录下创建PersonTest
package com.zbbmeta;import com.zbbmeta.entity.Person;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class PersonTest {@Testpublic void test(){//1.创建IOC容器ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("application-person.xml");//2.获取对象Person person = ac.getBean(Person.class); //根据指定类型去IOC容器中查找对象//3.打印对象System.out.println(person);//4.关闭容器ac.close();}
}
相关文章:
![](https://img-blog.csdnimg.cn/img_convert/f13afb3e2066f0746c9ff414cb120028.png)
Spring-1-深入理解Spring XML中的依赖注入(DI):简化Java应用程序开发
学习目标 前两篇文章我们介绍了什么是Spring,以及Spring的一些核心概念,并且快速快发一个Spring项目,以及详细讲解IOC,今天详细介绍一些DI(依赖注入) 能够配置setter方式注入属性值 能够配置构造方式注入属性值 能够理解什么是自动装配 一、…...
![](https://img-blog.csdnimg.cn/da7d9e75a4f34385a0b60b565c03ed6f.png#pic_center)
负载均衡–HAProxy安装及搭建tidb数据库负载服务
作为一名开发人员,随着经验的增加和技术的沉淀,需要提高自己架构方面的知识,同时对于一个企业来说,搭建一套高可用、高性能的技术架构,对于公司的业务开展和提高服务的性能也是大有裨益的。本文重点从软件安装和搭建ti…...
![](https://www.ngui.cc/images/no-images.jpg)
Django各种缓存的配置
Django提供了多种缓存后端,如内存缓存、文件缓存、数据库缓存、Memcached和Redis等。根据项目需求选择合适的缓存后端。 settings配置 在Django项目的settings.py文件中,找到或新增CACHES配置项。根据所选的缓存后端,配置相应的参数。以下是…...
![](https://img-blog.csdnimg.cn/6ec0a609957a4fbd86fd6ccff31bb167.png)
实现跨域的几种方式
原理 前后端的分离导致了跨域的产生 跨域的三要素:协议 域名 端口 三者有一个不同即产生跨域 例如: http://www.csdn.com https://www.csdn.com 由于协议不同,端口不同而产生跨域 注:http的默认端口80,https的默…...
![](https://img-blog.csdnimg.cn/ec0a5997da464299b93cca93cccaf6b4.png)
OpenCV: 对“google::protobuf::internal::Release_CompareAndSwap”的未定义
解决办法: 需要在文件 protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h 中的以下补丁 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, …...
![](https://www.learnfk.com/guide/images/wuya.png)
无涯教程-Perl - References(引用)
Perl引用是一个标量数据类型,该数据类型保存另一个值的位置,该值可以是标量,数组或哈希。 创建引用 变量,子程序或值创建引用很容易,方法是在其前面加上反斜杠,如下所示: $scalarref \$foo; $arrayref …...
![](https://img-blog.csdnimg.cn/a307b049eba548b581250b61709176ec.jpeg)
马斯克收购AI.com域名巩固xAI公司地位;如何评估大型语言模型的性能
🦉 AI新闻 🚀 AI拍照小程序妙鸭相机上线商业工作站并邀请摄影师进行内测 摘要:AI拍照小程序妙鸭相机将上线面向商业端的工作站,并邀请摄影师进行模板设计的内测。妙鸭相机希望为行业提供更多生态产品,扩大行业规模&a…...
![](https://img-blog.csdnimg.cn/548e45b1ecb9453a862cdae092e0780d.png)
uni-app:实现点击按钮出现底部弹窗(uni.showActionSheet+自定义)
一、通过uni.showActionSheet实现底部选择 效果 代码 <template><view><button click"showActionsheet">点击打开弹窗</button></view> </template><script> export default {methods: {showActionsheet() {uni.showAct…...
![](https://www.ngui.cc/images/no-images.jpg)
flume系列之:监控zookeeper的flume配置写入节点,新增和删除flume agent节点,通过ansible自动部署和卸载flume agent
flume系列之:监控zookeeper的flume配置写入节点,新增和删除flume agent节点,通过ansible自动部署和卸载flume agent 一、相关技术二、流程梳理三、部署和删除flume agent效果四、监控zookeeper节点五、新增zookeeper节点部署flume agent六、删除zookeeper节点删除flume agen…...
![](https://img-blog.csdnimg.cn/ee7208b7e45741dbb451a2ed5a539a5f.png)
了解以太网通信中的九阳神功 - SOME/IP协议
智能座舱SOME/IP通信 概述SOME/IP基础协议SOME/IP SD协议通信行为流程开机流程关机行为行为时序总结概述 SOME/IP协议是目前国内座舱SOA化应用比较广泛的一种ECU或车辆网络内设备之间交换数据的网络通信协议。它允许不同车辆组件,如发动机控制单元、信息娱乐系统、车身控制模…...
![](https://www.ngui.cc/images/no-images.jpg)
redis List类型命令
在Redis中,List(列表)是一种有序的、可重复的数据结构,它支持插入、删除和获取元素的操作。以下是一些常见的Redis List类型命令: LPUSH:将一个或多个值从列表的左侧插入。LPUSH key value1 value2 ...其中…...
![](https://www.ngui.cc/images/no-images.jpg)
【博客685】prometheus 出现NaN场景以及如何去除干扰(Not a Number)
prometheus 出现NaN场景以及如何去除干扰(Not a Number) 1、在prometheus中使用NaN来表示无效数值或者结果 场景: 一些监控系统使用 NaN 作为空值或缺失值,但在 Prometheus 中 NaN 只是另一个浮点值。Prometheus 表示缺失数据的方式是让数据缺失。Prom…...
![](https://img-blog.csdnimg.cn/679a7650d2514ea3bd39d4570d3ec3d7.png)
【计算机网络】网络层协议 -- ICMP协议
文章目录 1. ICMP协议简介2. ICMP协议格式3. ping命令4. ping命令与端口号没有关系!!!5. traceroute命令 1. ICMP协议简介 ICMP(Internet Control Message Protocol,控制报文协议),用于在IP主机…...
![](https://www.ngui.cc/images/no-images.jpg)
机器学习---facebook的案例学习
import pandas as pd import matplotlib.pyplot as plt import seaborn as sbn from sklearn.model_selection import train_test_split,GridSearchCV from sklearn.preprocessing import StandardScaler from sklearn.neighbors import KNeighborsClassifier # 使用pandas读…...
![](https://img-blog.csdnimg.cn/dc3ef45a3e5a4b09a98f8328c765ec8b.png)
OpenMMLab MMDetectionV3.1.0-SAM(环境安装、模型测试、训练以及模型后处理工具)
OpenMMLab Playground 概况 当前通用目标检测的研究方向正在朝着大型多模态模型发展。除了图像输入之外,最近的研究成果还结合了文本模式来提高性能。添加文本模态后,通用检测算法的一些非常好的属性开始出现,例如: 可以利用大量…...
![](https://img-blog.csdnimg.cn/a9373228c4f647798c5e364935cee3a8.png)
ios_base::out和ios::out、ios_base::in和ios::in、ios_base::app和ios::app等之间有什么区别吗?
2023年8月2日,周三晚上 今天我看到了这样的两行代码: std::ofstream file("example.txt", std::ios_base::out);std::ofstream file("example.txt", std::ios::out);这让我产生了几个疑问: 为什么有时候用ios_base::o…...
![](https://www.ngui.cc/images/no-images.jpg)
PostgreSQL 使用SQL
发布主题 设置发布为true 这个语句是针对 PostgreSQL 数据库中的逻辑复制功能中的逻辑发布(Logical Publication)进行设置的。 PostgreSQL 中,逻辑复制是一种基于逻辑日志的复制方法,允许将数据更改从一个数据库实例复制到另一…...
![](https://www.ngui.cc/images/no-images.jpg)
Shell编程基础(十四)文本三剑客(grep)
文本三剑客(grep) 使用场景基本使用返回值参数 使用场景 主要用于查找,过滤文本数据;该数据可以来自文件,也可以来自管道流等等。 grep除了原有的实现,后来还出现了以下扩展实现 egrep:支持扩展…...
![](https://img-blog.csdnimg.cn/95325321e56b48f09f669e7328146538.png)
Linux root用户执行修改密码命令,提示 Permission denied
问题 linux系统中(ubuntu20),root用户下执行passwd命令,提示 passwd: Permission denied ,如下图: 排查 1.执行 ll /usr/bin/passwd ,查看文件权限是否正确,正常情况是 -rwsr-xr…...
![](https://img-blog.csdnimg.cn/eacafa161a0c4ef7af192c653c8416db.png)
Java面向对象学习第三部分
一、Static修饰符 static是静态的意思,基本概念如下: Static分类: 一般我们分类都是按照是否使用static修饰进行分类。分为静态变量(类变量)、实例变量。 静态变量和实例变量的比较: 比较,…...
![](https://img-blog.csdnimg.cn/eba6a102a2654811a6f8d3260b88d0e4.png)
python+vue生成条形码码并展示
需求 最近想做一个小工具,大概要实现这样的效果:后端生成条形码后,不保存到服务器,直接返回给前端展示。 大概思路是,通过 python-barcode库 生成条码的字节流,生成字节流后直接编码成base64格式返回给前…...
![](https://img-blog.csdnimg.cn/img_convert/20a0f2a197eea336efacdf9ffff49cd6.png)
在线高精地图生成算法调研
1.HDMapNet 整体的网络架构如图所示,最终的Decoder输出三个分支,一个语义分割,一个embedding嵌入分支,一个方向预测。然后通过后处理将这些信息处理成向量化的道路表示。 img2bev的方式之前有IPM,通过假设地面的高度都…...
![](https://img-blog.csdnimg.cn/8eea622ef0054d7db93d7b52bc1e716e.png)
【干货】商城系统的重要功能特性介绍
电子商务的快速发展,商城系统成为了企业开展线上销售的重要工具。一款功能强大、用户友好的商城系统能够有效提升企业的销售业绩,提供良好的购物体验。下面就商城系统的重要功能特性作一些简单介绍,帮助企业选择合适的系统,打造成…...
![](https://img-blog.csdnimg.cn/96f3390a51cc49a2953bfed8a07f8655.png)
MYSQL06高级_为什么使用索引、优缺点、索引的设计、方案、聚簇索引、联合索引、注意事项
文章目录 ①. 为什么使用索引②. 索引及其优缺点③. InnoDb - 索引的设计④. InnoDb中的索引方案⑤. 索引 - 聚簇索引⑥. 索引 - 二级索引⑦. B树索引的注意事项⑧. MyISAM中索引方案 ①. 为什么使用索引 ①. 索引是存储引擎用于快速找到数据记录的一种数据结构,就好比去图书馆…...
![](https://img-blog.csdnimg.cn/b77d184d1d7a489c8f7ded3b8b7efb39.png#pic_center)
LeetCode 130. 被围绕的区域
题目链接:130. 被围绕的区域 题目描述 给你一个 m x n 的矩阵 board ,由若干字符 ‘X’ 和 ‘O’ ,找到所有被 ‘X’ 围绕的区域,并将这些区域里所有的 ‘O’ 用 ‘X’ 填充。 示例1: 输入:board [[“…...
![](https://img-blog.csdnimg.cn/img_convert/62e9b2d7bfbe412f0fc281de1869ffba.png)
python中2等于2.0吗,python中【1:2】
本篇文章给大家谈谈python中2等于2.0吗,以及python中【1:2】,希望对各位有所帮助,不要忘了收藏本站喔。 变量和赋值 Python中的变量不需要声明, 直接定义即可. 会在初始化的时候决定变量的 “类型” 使用 来进行初始化和赋值操作 定义变量时…...
![](https://www.ngui.cc/images/no-images.jpg)
【2023年11月第四版教材】《第2章-信息技术发展(第一部分)》
《第2章-信息技术发展(第一部分)》 章节说明1 计算机软硬件2 计算机网络2.1 网络的作用范围2.2 OSI模型2.3 广域网协议2.4 网络协议2.5 TCP/IP2.6 软件定义网络(SDN)2.7 第五代移动通信技术 章节说明 大部分为新增内容࿰…...
![](https://img-blog.csdnimg.cn/21d1b54e782e446ab8f455caa2adff57.png)
【CSS】说说对BFC的理解
目录 一、概念 二、BFC的布局规则 三、设置BFC的常用方式 四、BFC的应用场景 1、解决浮动元素令父元素高度坍塌的问题 2、解决非浮动元素被浮动元素覆盖问题 3、解决外边距垂直方向重合的问题 五、总结 一、概念 我们在页面布局的时候,经常出现以下情况&am…...
![](https://www.ngui.cc/images/no-images.jpg)
ES6学习-Class类
class constructor 构造方法 this 代表实例对象 方法之间不需要逗号分隔,加了会报错。 typeof Point // "function" Point Point.prototype.constructor // true类的数据类型就是函数,类本身就指向构造函数。 类的所有方法都定义在类的pr…...
![](https://img-blog.csdnimg.cn/3b30f16555d0438a97bd43ef48049e4d.png#pic_center)
C语言经典小游戏之扫雷(超详解释+源码)
“少年气,是历尽千帆举重若轻的沉淀,也是乐观淡然笑对生活的豁达!” 今天我们学习一下扫雷游戏怎么用C语言来实现! 扫雷小游戏 1.游戏介绍2.游戏准备3.游戏实现3.1生成菜单3.2游戏的具体实现3.2.1初始化棋盘3.2打印棋盘3.3布置雷…...
![](/images/no-images.jpg)
宁波网站建设科技有限公司/站长之家权重查询
了解如何针对评估、分析和性能来调整和调优 G1 GC。 2013 年 8 月发布 垃圾优先型垃圾回收器 (G1 GC) 是适用于 Java HotSpot VM 的低暂停、服务器风格的分代式垃圾回收器。G1 GC 使用并发和并行阶段实现其目标暂停时间,并保持良好的吞吐量。当 G1 GC 确定有必要进…...
![](/images/no-images.jpg)
网站手机版跳转代码/微信营销软件
[b]Closure[/b]:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure)。它只不过是个"内层"的函数,由一个名字&…...
![](https://img-blog.csdnimg.cn/img_convert/bf6f1305c71a12f88b82e547bb2a7de2.png)
做网站公司599/黄页88网络营销宝典
在进行数据解析时,先来看看excel测试数据格式,这里采用接口和测试数据分离的方式,即分为两个sheet页签分别存放接口信息,用例信息excel封装成对象步骤1、导入easypoi的坐标2、加载excel的流对象3、导入参数对象ImportParams4、工具…...
![](https://img-blog.csdnimg.cn/4559924732764c1aa1232ad7480e4a6a.gif)
冷库网站建设毕业论文/广州权威发布
实战需求 vlookup如何实现三变量查找,三个条件字段查询数据? 文章目录 《示例 1 – 查找 Brad 的数学分数》《示例 2 – 双向查找》《示例 3 – 使用下拉列表作为查找值》《示例 4 – 三向查找》什么是三向查找? 在示例 2 中,我们使用了一个查找表,其中包含不同科目学…...
免费文字变形logo设计/seo课堂
表单提交时 form submit 直接就可以提交了,但是了防止跨站攻击,都可以加入CSRF来防御。 node下的配置 var csrf require(csurf);app.use(csrf());app.use(function(req, res, next){let _csrf req.csrfToken();res.locals.csrf _csrf;res.cookie(XSRF…...
![](/images/no-images.jpg)
菏泽做网站的公司/网站搜索优化
总有许多人在讨论C的是是非非,我是人云亦云那个。 当你试图拥有两个以上类的特性时: 1 组合,用一个新类把那两个类的对象包含起来。很方便,很简单。缺点是:首先,会有太多的接口函数存在于两个基类对象与外…...