Spring IOC的四种手动注入方法

手动注入

  • 1.Set方法注入-五种类型的注入
    • 1.1 业务对象JavaBean
      • 第一步:创建dao包下的UserDao类
      • 第二步:属性字段提供set⽅法
      • 第三步:配置⽂件的bean标签设置property标签
      • 第四步:测试
    • 1.2 常用对象String(日期类型)| 基本类型Integer
      • 第一步:属性字段提供 set ⽅法
      • 第二步:配置⽂件的 bean 标签设置 property 标签
      • 第三步:测试
    • 1.3 集合类型和属性对象
      • 第一步:属性字段提供set⽅法
      • 第二步:配置⽂件的bean标签设置property标签
      • 第三步:测试
  • 2.构造器方法注入-种形式的注入
    • 2.1 单个Bean对象作为参数
      • 第一步:JavaBean对象
      • 第二步:XML配置
      • 第三步:测试
    • 2.2 多个Bean对象作为参数
      • 第一步:JavaBean对象
      • 第二步:XML配置
      • 第三步:测试
    • 2.3 Bean对象和常⽤对象作为参数
      • 第一步:加入常用对象String(举例)
      • 第二步:XML配置
      • 第三步:测试
    • 2.4 循环依赖问题
      • 问题示例
      • 问题解决
  • 3.静态工厂注入(了解)
    • 第一步:创建工厂类
    • 第二步:创建dao实体类
    • 第三步:创建TypeService,注入TypeDao
    • 第四步:xml配置
    • 第五步:测试
  • 4.实例化工厂注入(了解)
    • 4.1 定义实例化工厂,写非静态方法
    • 4.2 修改xml配置
  • 注入方式的选择
  • p名称空间的使用(了解)
    • 第一步:属性字段提供set方法
    • 第二步:在配置文件xml引入p名称空间

Spring ⽀持的注⼊⽅式共有四种:set 注⼊、构造器注⼊、静态⼯⼚注⼊、实例化⼯⼚注⼊
注:注入前提均建立在建立好的spring环境内

1.Set方法注入-五种类型的注入

以业务对象JavaBean为主

1.1 业务对象JavaBean

第一步:创建dao包下的UserDao类

package com.svt.dao;

public class UserDao {
    public void test(){
        System.out.println("UserDao Test...");
    }
}

第二步:属性字段提供set⽅法

原先写的方式都是手动实例化,比如private UserDao userDao=new UserDao();,这样会耦合过高,所以我们采用了新的形式:注入

package com.svt.service;

import com.svt.dao.UserDao;

public class UserService {

    //手动实例化
    //private UserDao userDao=new UserDao();

    //业务逻辑对象JavaBean 提供set方法注入
    //在配置文件中还未告知set方法注入 所以userDao是空的
    //将这里bean对象实例化的过程交给IOC去做
    private UserDao userDao;

    //set方法
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void test(){
        System.out.println("UserService Test...");
        userDao.test();
    }
}

第三步:配置⽂件的bean标签设置property标签

通过property属性实现注入

<?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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--
        Set方法注入
            通过property属性注入

    -->
    <bean id="userService" class="com.svt.service.UserService">
        <!--
            name:bean对象中属性字段的名称
            ref:指定bean标签的id属性值
        -->
        <property name="userDao" ref="userDao" />
    </bean>

    <bean id="userDao" class="com.svt.dao.UserDao"></bean>

</beans>

如果没有在资源文件夹xml内通过property属性实现注入,那么会出现空指针异常

在这里插入图片描述

第四步:测试

在UserService类中写测试方法

public void test(){
        System.out.println("UserService Test...");
        //JavaBean对象
        userDao.test();
    }

再在测试类中调用

import com.svt.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Starter01 {
    public static void main(String[] args) {
        //获取Spring的上下文环境 BeanFactory也是可以的
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");

        UserService userService= (UserService) ac.getBean("userService");
        userService.test();

    }
}

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

1.2 常用对象String(日期类型)| 基本类型Integer

第一步:属性字段提供 set ⽅法

    //常用对象String(日期类型)
    private String host;
    public void setHost(String host) {
        this.host = host;
    }

    //基本类型 Integer
    private Integer port;
    public void setPort(Integer port) {
        this.port = port;
    }

第二步:配置⽂件的 bean 标签设置 property 标签

		<!-- value:具体的值(基本类型 常用对象|日期  集合)-->
        <!-- 常用对象 String-->
        <property name="host" value="127.0.0.1"/>
        <!-- 基本类型Integer-->
        <property name="port" value="8080"/>

第三步:测试

在UserService类中写测试方法

public void test(){
        System.out.println("UserService Test...");
        //常用对象
        System.out.println(host);
        //基本类型
        System.out.println(port);
    }

再在测试类中调用

import com.svt.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Starter01 {
    public static void main(String[] args) {
        //获取Spring的上下文环境 BeanFactory也是可以的
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");

        UserService userService= (UserService) ac.getBean("userService");
        userService.test();

    }
}

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

1.3 集合类型和属性对象

第一步:属性字段提供set⽅法

//List集合
    private List<String> list;
    public void setList(List<String> list) {
        this.list = list;
    }
    //List输出
    public void printList(){
        list.forEach(v-> System.out.println(v));//jdk8提供
    }

    //Set集合
    private Set<String> sets;
    public void setSets(Set<String> sets) {
        this.sets = sets;
    }
    //Set输出
    public void printSet(){
        sets.forEach(v-> System.out.println(v));
    }

    //Map集合
    private Map<String,Object> map;
    public void setMap(Map<String, Object> map) {
        this.map = map;
    }
    //Map输出
    public void printMap(){
        map.forEach((k,v)-> System.out.println(k+"="+v));
    }

    //Properties属性对象
    private Properties properties;
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
    //Properties输出
    public void printProperties(){
        properties.forEach((k,v)-> System.out.println(k+"="+v));
    }

第二步:配置⽂件的bean标签设置property标签

<!--        List集合-->
        <property name="list">
            <list>
                <value>江苏</value>
                <value>浙江</value>
                <value>上海</value>
            </list>
        </property>

        <!--        Set集合-->
        <property name="sets">
            <set>
                <value>江苏JS</value>
                <value>浙江ZJ</value>
                <value>上海SH</value>
            </set>
        </property>

        <!--        Map集合-->
        <property name="map">
            <map>
                <entry>
                    <key>
                        <value>周杰伦</value>
                    </key>
                    <value>晴天</value>
                </entry>
                <entry>
                    <key>
                        <value>林俊杰</value>
                    </key>
                    <value>美人鱼</value>
                </entry>
                <entry>
                    <key>
                        <value>陈奕迅</value>
                    </key>
                    <value>富士山下</value>
                </entry>
            </map>
        </property>

        <!--        Properties属性对象-->
        <property name="properties">
            <props>
                <prop key="js">江苏</prop>
                <prop key="zj">浙江</prop>
                <prop key="sh">上海</prop>
            </props>
        </property>

第三步:测试

与上面一样

public void test(){
        System.out.println("UserService Test...");
        //List集合类型
        printList();
        //Set集合类型
        printSet();
        //Map集合类型
        printMap();
        //Properties属性对象
        printProperties();
    }

在这里插入图片描述

2.构造器方法注入-种形式的注入

2.1 单个Bean对象作为参数

第一步:JavaBean对象

package com.svt.service;

import com.svt.dao.UserDao02;

/**
 * 构造器方法注入
 *  需要提供带参构造
 */
public class UserService02 {
    private UserDao02 userDao02;
    /* 构造器注入*/

    public UserService02(UserDao02 userDao02) {
        this.userDao02 = userDao02;
    }
    public void test(){
        System.out.println("UserService Test...");
    }
}

第二步: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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--
        构造器注入
            设置构造器所需要的参数
            通过constructor-arg标签设置构造器的参数
                name:属性名称
                ref:要注入的bean对象对应的bean标签的id属性值
    -->
    <bean id="userService02" class="com.svt.service.UserService02">
        <constructor-arg name="userDao02" ref="userDao02"></constructor-arg>
    </bean>

    <bean id="userDao02" class="com.svt.dao.UserDao02"></bean>

</beans>

第三步:测试

import com.svt.service.UserService02;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Starter02 {
    public static void main(String[] args) {
        //获取Spring的上下文环境 BeanFactory也是可以的
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring02.xml");

        UserService02 userService02= (UserService02) ac.getBean("userService02");
        userService02.test();

    }
}

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

2.2 多个Bean对象作为参数

第一步:JavaBean对象

package com.svt.service;

import com.svt.dao.UserDao;
import com.svt.dao.UserDao02;

/**
 * 构造器方法注入
 *  需要提供带参构造
 */
public class UserService02 {
    private UserDao02 userDao02;
    /* 构造器注入*/

    /*public UserService02(UserDao02 userDao02) {
        this.userDao02 = userDao02;
    }*/

    private UserDao userDao;

    public UserService02(UserDao02 userDao02, UserDao userDao) {
        this.userDao02 = userDao02;
        this.userDao = userDao;
    }

    public void test(){
        System.out.println("UserService Test...");
        userDao02.test();
        userDao.test();
    }
}

第二步: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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--
        构造器注入
            设置构造器所需要的参数
            通过constructor-arg标签设置构造器的参数
                name:属性名称
                ref:要注入的bean对象对应的bean标签的id属性值
                value:数据具体的值
                index:参数的位置(从0开始)一般不用 但是可以确定参数是哪个位置的
    -->
    <bean id="userService02" class="com.svt.service.UserService02">
        <constructor-arg name="userDao02" ref="userDao02"></constructor-arg>
        <constructor-arg name="userDao" ref="userDao"></constructor-arg>

    </bean>

    <bean id="userDao02" class="com.svt.dao.UserDao02"></bean>
    <bean id="userDao" class="com.svt.dao.UserDao"></bean>

</beans>

如果在写完JavaBean对象而没有在配置文件中添加bean则会出现以下报错内容,像上面xml文件中一样添加 <constructor-arg name="userDao" ref="userDao"></constructor-arg>即可
在这里插入图片描述

第三步:测试

在UserService02中的test测试方法中新增了两行输出语句

public void test(){
        System.out.println("UserService Test...");
        userDao02.test();
        userDao.test();
    }

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

2.3 Bean对象和常⽤对象作为参数

第一步:加入常用对象String(举例)

	private UserDao02 userDao02;
    /* 构造器注入*/

    private UserDao userDao;
    
    private String user;

    public UserService02(UserDao02 userDao02, UserDao userDao, String user) {
        this.userDao02 = userDao02;
        this.userDao = userDao;
        this.user = user;
    }

第二步: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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--
        构造器注入
            设置构造器所需要的参数
            通过constructor-arg标签设置构造器的参数
                name:属性名称
                ref:要注入的bean对象对应的bean标签的id属性值
                value:数据具体的值
                index:参数的位置(从0开始)一般不用 但是可以确定参数是哪个位置的
    -->
    <bean id="userService02" class="com.svt.service.UserService02">
        <constructor-arg name="userDao02" ref="userDao02"></constructor-arg>
        <constructor-arg name="userDao" ref="userDao"></constructor-arg>
        <constructor-arg name="user" value="user" index=""></constructor-arg>

    </bean>

    <bean id="userDao02" class="com.svt.dao.UserDao02"></bean>
    <bean id="userDao" class="com.svt.dao.UserDao"></bean>

</beans>

在这里插入图片描述

第三步:测试

在UserService02中的test测试方法中新增了一行输出语句

public void test(){
        System.out.println("UserService Test...");
        userDao02.test();
        userDao.test();
        System.out.println(user);
    }

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

2.4 循环依赖问题

产生原因:Bean 通过构造器注⼊,之间彼此相互依赖对⽅导致 bean ⽆法实例化。比如一个IOC容器要去实例化A,但是A中有B的注入,于是IOC就先去找B实例化,此时B中又有A的注入,IOC又要去找A先进行初始化,这样一套下来IOC不知道是先找A还是B就会出现循环依赖的问题。

问题示例

  • 代码示例
public class AccountService {
    private AccountDao accountDao;

    public AccountService(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public void test(){
        System.out.println("AccountService Test...");
        accountDao.test();
    }
}

public class AccountDao {
    private AccountService accountService;

    public AccountDao(AccountService accountService) {
        this.accountService = accountService;
    }

    public void test(){
        System.out.println("AccountDao Test...");
    }
}

  • 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
		https://www.springframework.org/schema/beans/spring-beans.xsd">
<!--    循环依赖问题-->
    <bean id="acountService" class="com.svt.service.AccountService">
        <constructor-arg name="accountDao" ref="accountDao"></constructor-arg>
    </bean>
    <bean id="accountDao" class="com.svt.dao.AccountDao">
        <constructor-arg name="accountService" ref="acountService"></constructor-arg>
    </bean>
</beans>

此时AccountDao 注入了AccountService ,而AccountService 也注入了AccountDao ,这就造成了循环依赖
在这里插入图片描述

问题解决

如果出现循环依赖 需要通过set注入解决,下面就依据上面的循环注入代码进行解决

  • 解决代码示例
public class AccountDao {
    private AccountService accountService;
    
    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    public void test(){
        System.out.println("AccountDao Test...");
    }
}

public class AccountService {
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public void test(){
        System.out.println("AccountService Test...");
        accountDao.test();
    }
}

  • 解决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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--    如果出现循环依赖 需要通过set注入解决-->

    <bean id="accountService" class="com.svt.service.AccountService">
        <property name="accountDao" ref="accountDao"></property>
    </bean>
    <bean id="accountDao" class="com.svt.dao.AccountDao">
        <property name="accountService" ref="accountService"></property>
    </bean>
    <!--
        构造器必须等待构造器参数中的实例化实例化好后才会实例化本身
        set方法注入:先实例化对象,再找被注入的set进去,就不会造成循环依赖
    -->
</beans>

原因

  • 构造器注入:必须等待构造器参数中的实例化实例化好后才会实例化本身
  • set方法注入:先实例化对象,再找被注入的set进去,就不会造成循环依赖
    在这里插入图片描述

3.静态工厂注入(了解)

第一步:创建工厂类

new factory->new StaticFactory

package com.svt.factory;

import com.svt.dao.TypeDao;

//静态工厂
public class StaticFactory {
    //定义静态方法
    public static TypeDao createTypeDao(){
        return new TypeDao();
    }
}

第二步:创建dao实体类

package com.svt.dao;

public class TypeDao {
    public void test(){
        System.out.println("TypeDao Test...");
    }
}

第三步:创建TypeService,注入TypeDao

package com.svt.service;

import com.svt.dao.TypeDao;

public class TypeService {
    //注入TypeDao
    private TypeDao typeDao;

    public void setTypeDao(TypeDao typeDao) {
        this.typeDao = typeDao;
    }

    public void test(){
        System.out.println("TypeService Test...");
        typeDao.test();
    }
}

第四步: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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--    静态工厂-->
    <!--    定义bean对象-->
    <bean id="typeService" class="com.svt.service.TypeService">
        <property name="typeDao" ref="typeDao"></property>
    </bean>
<!--    静态工厂注入:通过静态构造实例化需要被注入的bean对象-->
    <bean id="typeDao" class="com.svt.factory.StaticFactory" factory-method="createTypeDao"></bean>
</beans>

第五步:测试


import com.svt.service.TypeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Starter02 {
    public static void main(String[] args) {
        //获取Spring的上下文环境 BeanFactory也是可以的
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring02.xml");

        TypeService typeService= (TypeService) ac.getBean("typeService");
        typeService.test();

    }
}

在这里插入图片描述
出现测试类中展现的内容则代表注入无误

4.实例化工厂注入(了解)

实例化工厂注入与静态工厂注入大致一样,有以下几点不同

4.1 定义实例化工厂,写非静态方法

静态工厂里写的是静态方法,实例化工厂里写的非静态方法

package com.svt.factory;

import com.svt.dao.TypeDao;

//定义实例化工厂
public class InstanceFactory {
    public TypeDao createTypeDao(){
        return new TypeDao();
    }
}

4.2 修改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
		https://www.springframework.org/schema/beans/spring-beans.xsd">

    <!--    定义bean对象-->
    <bean id="typeService" class="com.svt.service.TypeService">
        <property name="typeDao" ref="typeDao"></property>
    </bean>
    
<!--    实例化工厂注入:通过实例化工厂需要被注入的bean对象-->
    <bean id="instanceFactory" class="com.svt.factory.InstanceFactory"></bean>
    <bean id="typeDao" factory-bean="instanceFactory" factory-method="createTypeDao"></bean>
</beans>

其余与静态工厂一致,测试类实现结果也与静态工厂一致
静态工厂注入与实例化工厂注入本质上还是set注入,只是本来bean对象是通过构造器去实例化的,现在更换了以下,想要静态工厂注入就把实例化的方式变成静态工厂,实例化工厂同理,两者用的不多,理解即可

注入方式的选择

开发项⽬中set⽅式注⼊⾸选
使⽤构造注⼊可以在构建对象的同时⼀并完成依赖关系的建⽴,对象⼀建⽴则所有的⼀切也就准备好
了,但如果要建⽴的对象关系很多,使⽤构造器注⼊会在构建函数上留下⼀⻓串的参数,且不易记忆,这时使⽤Set注⼊会是个不错的选择。
使⽤Set注⼊可以有明确的名称,可以了解注⼊的对象会是什么,像setXXX()这样的名称会⽐记忆Constructor上某个参数的位置代表某个对象更好。

p名称空间的使用(了解)

spring2.5以后,为了简化setter方法属性注入,引用p名称空间的概念,可以将子元素,简化为元素属性配置。

第一步:属性字段提供set方法

package com.svt.service;

import com.svt.dao.UserDao;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * Set方法注入
 * 1.属性字段提供set方法
 * 2.在配置文件中通过property属性指定属性字段
 */
public class UserService03 {

    //手动实例化
    //private UserDao userDao=new UserDao();

    //业务逻辑对象JavaBean 提供set方法注入
    //在配置文件中还未告知set方法注入 所以userDao是空的
    //将这里bean对象实例化的过程交给IOC去做
    private UserDao userDao;
    //set方法
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }


    //常用对象String(日期类型)
    private String host;
    public void setHost(String host) {
        this.host = host;
    }

    public void test(){
        System.out.println("UserService Test...");
        //JavaBean对象
        userDao.test();

    }
}

第二步:在配置文件xml引入p名称空间

xmlns:p="http://www.springframework.org/schema/p"
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!--    p名称空间:简化set属性的注入-->
    <bean id="userDao" class="com.svt.dao.UserDao"></bean>
    <bean id="userService03" class="com.svt.service.UserService03"
          p:host="127.0.0.1"
          p:userDao-ref="userDao"
    >

    </bean>
	<!--
		p:属性名:="xxx 引入常量值
		p:属性名-ref;="xxx" 引入其他Bean对象的id属性值
	-->
</beans>

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【AI视野·今日CV 计算机视觉论文速览 第282期】Wed, 3 Jan 2024

AI视野今日CS.CV 计算机视觉论文速览 Wed, 3 Jan 2024 Totally 70 papers &#x1f449;上期速览✈更多精彩请移步主页 Daily Computer Vision Papers Street Gaussians for Modeling Dynamic Urban Scenes Authors Yunzhi Yan, Haotong Lin, Chenxu Zhou, Weijie Wang, Haiya…

togaf 9.2中文版

尊敬的读者朋友们&#xff0c;本专栏为togaf 9.2 的个人学习笔记&#xff0c;我会尽量将信息完整地传递给大家&#xff0c;以便更多对 togaf 感兴趣的朋友不用花费巨资去购买相关资料。本文档不需要读者具备企业架构的预备知识。 专栏受众&#xff1a;企业架构师、业务架构师、…

Android WiFi 连接

Android WiFi 连接 1、设置中WiFi显示2、WiFi 连接流程2.1 获取PrimaryClientModeManager2.2 ClientModeImpl状态机ConnectableState2.3 ISupplicantStaNetworkCallback 回调监听 3、 简要时序图4、原生低层驱动5、关键日志 1、设置中WiFi显示 Android WiFi基础概览 packages/a…

阿里云服务器可用区是什么?

阿里云服务器地域和可用区怎么选择&#xff1f;地域是指云服务器所在物理数据中心的位置&#xff0c;地域选择就近选择&#xff0c;访客距离地域所在城市越近网络延迟越低&#xff0c;速度就越快&#xff1b;可用区是指同一个地域下&#xff0c;网络和电力相互独立的区域&#…

天津最新web前端培训班 如何提升web技能?

随着互联网的迅猛发展&#xff0c;web前端成为了一个热门的职业方向。越来越多的人希望能够通过学习web前端技术来提升自己的就业竞争力。为了满足市场的需求&#xff0c;许多培训机构纷纷推出了web前端培训课程。 什么是WEB前端 web前端就是web给用户展示的东西&#xff0c;…

DataFunSummit:2023年知识图谱在线峰会-核心PPT资料下载

一、峰会简介 AIGC&#xff0c;ChatGPT以及发布的GPT-4相信已经给大家带来足够的冲击&#xff0c;那么对于知识图谱的应用产生哪些变化和变革&#xff1f;知识图谱在其中如何发挥作用呢&#xff1f;通过LLM是否有可能辅助创建通用大规模知识图谱&#xff1f;AIGC时代下行业知识…

http缓存

http缓存 header里缓存相关的属性 Expires 响应头,代表该资源的过期时间&#xff0c;在http1.0引入Cache-control 请求/响应头&#xff0c;可以配置缓存策略&#xff0c;在http1.1引入&#xff0c;与Expires同时存在时&#xff0c;优先使用Cache-controlIf-Modified-Since …

实现在一个文件夹中找到特定名称特点格式的文件

当你要在一个文件夹中查找特定名称和格式的文件时&#xff0c;你可以使用 Python 的 os 和 fnmatch 模块。以下是一个简单的脚本示例&#xff0c;它可以在指定目录中查找文件&#xff1a; import os import fnmatchdef find_files(directory, pattern):"""在指…

关于图像分割任务中按照比例将数据集随机划分成训练集和测试集

1. 前言 之前写了分类和检测任务划分数据集的脚本&#xff0c;三大任务实现了俩&#xff0c;基于强迫症&#xff0c;也实现一下图像分割的划分脚本 分类划分数据&#xff1a;关于图像分类任务中划分数据集&#xff0c;并且生成分类类别的josn字典文件 检测划分数据&#xff…

【IDEA】 解决在idea中连接 Mysql8.0,驱动无法下载问题

本篇继【idea】解决sprintboot项目创建遇到的问题2-CSDN博客 目录 一、Failed to download https://download.jetbrains.com/idea/jdbc-drivers/MySQL/8/LICENSE.txt:Remote host terminated the handshake 二、no dirver files provided com.mysql.cj.jdbc.Driver 三、Serv…

leetcode“位运算”——只出现一次的数字

只出现一次的数字i&#xff1a; https://leetcode.cn/problems/single-number/ 给你一个非空整数数组 nums&#xff0c;除了某个元素只出现一次以外&#xff0c;其余每个元素均出现两次。找出那个只出现一次的元素。 class Solution { public:int singleNumber(vector<i…

flink table view datastream互转

case class outer(f1:String,f2:Inner) case class outerV1(f1:String,f2:Inner,f3:Int) case class Inner(f3:String,f4:Int) 测试代码 package com.yy.table.convertimport org.apache.flink.streaming.api.scala.StreamExecutionEnvironment import org.apache.flink.tabl…

强化学习的数学原理学习笔记 - 基于模型(Model-based)

文章目录 概览&#xff1a;RL方法分类基于模型&#xff08;Model-Based&#xff09;值迭代&#xff08;Value Iteration&#xff09;&#x1f7e6;策略迭代&#xff08;Policy Iteration&#xff09;&#x1f7e1;截断策略迭代&#xff08;Truncated Policy Iteration&#xff…

从新手到大师:四大编程范式解锁你的编码力!

编程&#xff0c;就是用代码跟计算机交流&#xff0c;告诉它我们想要它做什么。不同的编程范式就是不同的交流方式&#xff0c;每种方式都有自己独特的语法和规则。 今天&#xff0c;我们就来聊聊这四种主要的编程范式&#xff0c;它们分别是命令式、函数式、面向对象和声明式…

cube生成电机库,启用了RTOS,编译报错[0xc43ed8:5050106] in osSignalWait

cube生成电机库&#xff0c;启用了RTOS&#xff0c;编译报错[0xc43ed8:5050106&#xff0c;解决办法] in osSignalWait 1.现象 编译报错[0xc43ed8:5050106] in osSignalWait 导致链接失败 2.解决办法 将keil5的版本升级到5.18.00&#xff0c;我的版本也是5.14.00。

2024阿里云优惠活动有哪些?

2024年阿里云优惠活动大全&#xff0c;包括阿里云服务器优惠活动清单、配置价格表、域名优惠活动、阿里云建站活动、阿里云优惠代金券免费领取、对象存储OSS活动、企业邮箱优惠、无影云电脑优惠、CDN特惠等等&#xff0c;阿里云百科aliyunbaike.com分享2024阿里云优惠活动大全_…

Vue实现加减法验证码

引入Vue.js 在HTML文件的<head>标签中引入Vue.js的CDN链接&#xff1a; <script src"https://cdn.jsdelivr.net/npm/vue2.6.11/dist/vue.min.js"></script>创建Vue实例 接下来&#xff0c;我们要创建一个Vue实例&#xff0c;并将其挂载到HTML文…

用可视化案例讲Rust编程1. 怎么能学会Rust

用可视化案例讲Rust编程 1. 怎么能学会Rust 如果要列举Rust的优势&#xff0c;恐怕写个十条八条是写不完的&#xff0c;而且不管写哪条优势&#xff0c;都有很多同学跳起来反驳&#xff0c;比如我们说Rust比C/C内存安全&#xff0c;肯定有同学说C 20也支持内存安全&#xff0…

使用metricbeat 监控多ES集群

背景 ES 本身自带 监控&#xff0c;属于xpack 中的内容&#xff0c;为商业版&#xff0c;需要收费&#xff1b; 并且 monitor 功能必须要在security开启后才能使用&#xff0c;还有就是集群监控自己&#xff0c;将采集到的性能数据保存到本集群&#xff0c;这是一个比较差的设…

全网最全postman接口测试教程和项目实战~从入门到精通!!!

Postman实现接口测试内容大纲一览&#xff1a; 一、什么是接口&#xff1f;为什么需要接口&#xff1f; 接口指的是实体或者软件提供给外界的一种服务。 因为接口能使我们的实体或者软件的内部数据能够被外部进行修改。从而使得内部和外部实现数据交互。所以需要接口。 比如&…