依赖注入就是对类的属性进行赋值

4.1、环境搭建

创建名为spring_ioc_xml的新module,过程参考3.1节

4.1.1、创建spring配置文件

<?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"> </beans>

4.1.2、创建学生类Student

package org.rain.spring.pojo;

/**
* @author liaojy
* @date 2023/7/27 - 22:33
*/
public class Student { private Integer id;
private String name;
private Integer age;
private String sex; public Student() {
} public Student(Integer id, String name, Integer age, String sex) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} @Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
'}';
}
}

4.2、setter注入(常用)

4.2.1、配置bean

    <!--
property标签:通过组件类的setXxx()方法给组件对象设置属性
name属性:指定属性名
value属性:设置属性值
-->
<bean id="student" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
</bean>

4.2.2、测试

package org.rain.spring.test;

import org.junit.Test;
import org.rain.spring.pojo.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* @author liaojy
* @date 2023/7/27 - 22:43
*/
public class IOCByXmlTest { @Test
public void testDISetter(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("student", Student.class);
System.out.println(student);
}
}

4.3、构造器注入

4.3.1、配置bean

注意:constructor-arg标签的数量,必须和某一个构造器方法的参数数量一致

    <!--
constructor标签:通过组件类的有参构造方法给组件对象设置属性
name属性:指定有参构造方法参数名
value属性:设置有参构造方法参数值
-->
<bean id="studentTwo" class="org.rain.spring.pojo.Student">
<constructor-arg name="id" value="1002"></constructor-arg>
<constructor-arg name="name" value="李四"></constructor-arg>
<constructor-arg name="age" value="24"></constructor-arg>
<constructor-arg name="sex" value="女"></constructor-arg>
</bean>

4.3.2、测试

    @Test
public void testDIConstructor(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentTwo", Student.class);
System.out.println(student);
}

4.4、特殊值处理

4.4.1、null值

4.4.1.1、配置bean

注意:该<property name="sex" value="null">写法,实际为sex所赋的值是字符串null

    <bean id="studentThree" class="org.rain.spring.pojo.Student">
<property name="id" value="1003"></property>
<property name="name" value="张三"></property>
<property name="sex" >
<null></null>
</property>
</bean>

4.4.1.2、测试

由控制台日志可知,此时sex的值为null

    @Test
public void testDIspecial(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentThree", Student.class);
System.out.println(student.getSex().toString());
}

+++++++++++++++++++++++++++++++++++分割线+++++++++++++++++++++++++++++++++++

由控制台日志可知,此时age的值也为null;所以不配置属性也能实现同样的效果

4.4.2、xml字符值

4.4.2.1、方式一:实体

    <bean id="studentThree" class="org.rain.spring.pojo.Student">
<property name="id" value="1003"></property>
<!--用实体来代替xml字符-->
<property name="name" value="&lt;张三&gt;"></property>
<property name="sex" >
<null></null>
</property>
</bean>

4.4.2.2、方式二:CDATA节

    <bean id="studentThree" class="org.rain.spring.pojo.Student">
<property name="id" value="1003"></property>
<!-- CDATA中的C代表Character,是文本、字符的含义,CDATA就表示纯文本数据 -->
<!-- XML解析器看到CDATA节就知道这里是纯文本,就不会当作XML标签或属性来解析 -->
<!-- 所以CDATA节中写什么符号都随意 -->
<property name="name">
<value><![CDATA[<张三>]]></value>
</property>
<property name="sex" >
<null></null>
</property>
</bean>

4.4.2.3、测试

4.5、为类类型的属性赋值

4.5.1、方式一:外部bean(常用)

4.5.1.1、创建班级类Clazz

package org.rain.spring.pojo;

/**
* @author liaojy
* @date 2023/7/28 - 7:54
*/
public class Clazz {
private Integer cid;
private String cname; public Clazz() {
} public Clazz(Integer cid, String cname) {
this.cid = cid;
this.cname = cname;
} public Integer getCid() {
return cid;
} public void setCid(Integer cid) {
this.cid = cid;
} public String getCname() {
return cname;
} public void setCname(String cname) {
this.cname = cname;
} @Override
public String toString() {
return "Clazz{" +
"cid=" + cid +
", cname='" + cname + '\'' +
'}';
}
}

4.5.1.2、修改Student类

package org.rain.spring.pojo;

/**
* @author liaojy
* @date 2023/7/27 - 22:33
*/
public class Student { private Integer id;
private String name;
private Integer age;
private String sex; private Clazz clazz; public Student() {
} public Student(Integer id, String name, Integer age, String sex, Clazz clazz) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
this.clazz = clazz;
} public Clazz getClazz() {
return clazz;
} public void setClazz(Clazz clazz) {
this.clazz = clazz;
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} @Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", clazz=" + clazz +
'}';
}
}

4.5.1.3、配置外部bean

    <bean id="clazz" class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean>

4.5.1.4、引用外部bean

    <bean id="studentfour" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<!-- ref属性:引用IOC容器中某个bean的id,将所对应的bean为属性赋值 -->
<property name="clazz" ref="clazz"></property>
</bean>

4.5.1.5、测试

    @Test
public void testDIOuterBean(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentfour", Student.class);
System.out.println(student);
}

4.5.2、方式二、级联

4.5.2.1、配置bean

    <bean id="clazz" class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean> <bean id="studentFive" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<!-- 一定先引用某个bean为属性赋值,才可以使用级联方式更新属性 -->
<property name="clazz" ref="clazz"></property>
<property name="clazz.cid" value="2222"></property>
<property name="clazz.cname" value="五年A班"></property>
</bean>

4.5.2.2、测试

    @Test
public void testDICascade(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentFive", Student.class);
System.out.println(student);
}

4.5.3、内部bean(常用)

4.5.3.1、配置bean

    <bean id="studentSix" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<property name="clazz">
<!-- 内部bean只能用于给属性赋值,不能在外部通过IOC容器获取,因此可以省略id属性 -->
<bean class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean>
</property>
</bean>

4.5.3.2、测试

    @Test
public void testDIInnerBean(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentSix", Student.class);
System.out.println(student);
}

4.6、为数组类型的属性赋值

4.6.1、修改Student类

在Student类中添加或修改以下代码:

    private String hobby[];

    public String[] getHobby() {
return hobby;
} public void setHobby(String[] hobby) {
this.hobby = hobby;
} @Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", clazz=" + clazz +
", hobby=" + Arrays.toString(hobby) +
'}';
}

4.6.2、配置bean

    <bean id="studentSeven" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<property name="clazz">
<bean class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean>
</property>
<property name="hobby">
<array>
<!--如果数组类型是基本类型和string类型,就用value标签-->
<!--如果数组类型是类类型,就用ref标签-->
<value>游泳</value>
<value>跑步</value>
<value>骑车</value>
</array>
</property>
</bean>

4.6.3、测试

    @Test
public void testDIArray(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentSeven", Student.class);
System.out.println(student);
}

4.7、为List集合类型的属性赋值

4.7.1、修改Clazz类

在Clazzt类中添加或修改以下代码:


private List<Student> students; public List<Student> getStudents() {
return students;
} public void setStudents(List<Student> students) {
this.students = students;
} @Override
public String toString() {
return "Clazz{" +
"cid=" + cid +
", cname='" + cname + '\'' +
", students=" + students +
'}';
}

4.7.2、配置bean

    <bean id="student" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
</bean> <bean id="studentThree" class="org.rain.spring.pojo.Student">
<property name="id" value="1003"></property>
<property name="name">
<value><![CDATA[<张三>]]></value>
</property>
<property name="sex" >
<null></null>
</property>
</bean> <bean id="clazz" class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean> <bean id="studentfour" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<property name="clazz" ref="clazz"></property>
</bean> <bean id="clazzTwo" class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
<property name="students">
<list>
<!--如果list集合元素是基本类型和string类型,就用value标签-->
<!--如果list集合元素是类类型,就用ref标签-->
<ref bean="student"></ref>
<ref bean="studentThree"></ref>
<ref bean="studentfour"></ref>
</list>
</property>
</bean>

4.7.3、测试

    @Test
public void testDIList(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Clazz clazz = applicationContext.getBean("clazzTwo", Clazz.class);
System.out.println(clazz);
}

4.8、为Map集合类型的属性赋值

4.8.1、创建教师类Teacher

package org.rain.spring.pojo;

/**
* @author liaojy
* @date 2023/7/30 - 12:10
*/
public class Teacher {
private Integer tid;
private String tname; public Teacher() {
} public Teacher(Integer tid, String tname) {
this.tid = tid;
this.tname = tname;
} public Integer getTid() {
return tid;
} public void setTid(Integer tid) {
this.tid = tid;
} public String getTname() {
return tname;
} public void setTname(String tname) {
this.tname = tname;
} @Override
public String toString() {
return "Teacher{" +
"tid=" + tid +
", tname='" + tname + '\'' +
'}';
}
}

4.8.2、修改Student类

在Student类中添加或修改以下代码:

    private Map<String,Teacher> teacherMap;

    public Map<String, Teacher> getTeacherMap() {
return teacherMap;
} public void setTeacherMap(Map<String, Teacher> teacherMap) {
this.teacherMap = teacherMap;
} @Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", clazz=" + clazz +
", hobby=" + Arrays.toString(hobby) +
", teacherMap=" + teacherMap +
'}';
}

4.8.3、配置bean

    <bean id="teacherOne" class="org.rain.spring.pojo.Teacher">
<property name="tid" value="10010"></property>
<property name="tname" value="张老师"></property>
</bean> <bean id="teacherTwo" class="org.rain.spring.pojo.Teacher">
<property name="tid" value="10086"></property>
<property name="tname" value="李老师"></property>
</bean> <bean id="studentEight" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<property name="clazz">
<bean class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean>
</property>
<property name="hobby">
<array>
<value>游泳</value>
<value>跑步</value>
<value>骑车</value>
</array>
</property>
<property name="teacherMap">
<map>
<!--如果键是字面量,就用key属性,否则用key-ref属性 -->
<!--如果值是字面量,就用value属性,否则用value-ref属性 -->
<entry key="10010" value-ref="teacherOne"></entry>
<entry key="10086" value-ref="teacherTwo"></entry>
</map>
</property>
</bean>

4.8.4、测试

    @Test
public void testDIMap(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentEight", Student.class);
System.out.println(student);
}

4.9、为集合类型的属性赋值(解耦引用方式)

4.9.1、配置bean

注意:使用util:list、util:map标签必须引入相应的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" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <!--list集合类型的bean-->
<util:list id="students">
<ref bean="student"></ref>
<ref bean="studentThree"></ref>
<ref bean="studentfour"></ref>
</util:list> <!--map集合类型的bean-->
<util:map id="teacherMap">
<entry key="10010" value-ref="teacherOne"></entry>
<entry key="10086" value-ref="teacherTwo"></entry>
</util:map> <bean id="studentNine" class="org.rain.spring.pojo.Student">
<property name="id" value="0011"></property>
<property name="name" value="张三"></property>
<property name="age" value="23"></property>
<property name="sex" value="男"></property>
<property name="clazz">
<bean class="org.rain.spring.pojo.Clazz">
<property name="cid" value="1111"></property>
<property name="cname" value="三年E班"></property>
</bean>
</property>
<property name="hobby">
<array>
<value>游泳</value>
<value>跑步</value>
<value>骑车</value>
</array>
</property>
<property name="teacherMap" ref="teacherMap"> </property>
</bean> </beans>

4.9.2、测试

    @Test
public void testDIUtil(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentNine", Student.class);
System.out.println(student);
}

4.10、p命名空间(了解)

4.10.1、配置bean

注意:p命名空间的依赖注入,本质上是属性方式(setter方法)的依赖注入

<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <!--map集合类型的bean-->
<util:map id="teacherMap">
<entry key="10010" value-ref="teacherOne"></entry>
<entry key="10086" value-ref="teacherTwo"></entry>
</util:map> <bean id="studentTen" class="org.rain.spring.pojo.Student"
p:id="1001" p:name="张三" p:teacherMap-ref="teacherMap"></bean> </beans>

4.10.2、测试

    @Test
public void testDIP(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-ioc.xml");
Student student = applicationContext.getBean("studentTen", Student.class);
System.out.println(student);
}

4.11、引入外部属性文件

4.11.1、引入数据库相关依赖

        <!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<!-- 数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.31</version>
</dependency>

4.11.2、创建外部属性文件

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

4.11.3、配置bean

注意:使用context:property-placeholder标签必须引入相应的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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> <!--引入外部属性文件-->
<context:property-placeholder location="jdbc.properties"></context:property-placeholder> <bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource">
<!--通过${key}的方式访问外部属性文件的value-->
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> </beans>

4.11.4、测试

    @Test
public void testDIOuterFile() throws SQLException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-datasource");
DruidDataSource datasource = applicationContext.getBean("datasource", DruidDataSource.class);
System.out.println(datasource.getConnection());
}

4、Spring之依赖注入的更多相关文章

  1. (spring-第3回【IoC基础篇】)spring的依赖注入-属性、构造函数、工厂方法等的注入(基于XML)

    Spring要把xml配置中bean的属性实例化为具体的bean,"依赖注入"是关卡.所谓的"依赖注入",就是把应用程序对bean的属性依赖都注入到spring ...

  2. Spring的依赖注入(DI)三种方式

    Spring依赖注入(DI)的三种方式,分别为: 1.  接口注入 2.  Setter方法注入 3.  构造方法注入 下面介绍一下这三种依赖注入在Spring中是怎么样实现的. 首先我们需要以下几个 ...

  3. spring的依赖注入的最常见的两种方法

    package com.lsz.spring.action; public class User { /** * set注入 */ private String username; public vo ...

  4. 一步一步深入spring(3)--spring的依赖注入方式

    对于spring配置一个bean时,如果需要给该bean提供一些初始化参数,则需要通过依赖注入方式,所谓的依赖注入就是通过spring将bean所需要的一些参数传递到bean实例对象的过程,sprin ...

  5. spring的依赖注入是什么意思

    最近学习spring框架,对依赖注入有些模糊,遂上网翻阅资料,做了下列总结,原博客为CSDN 南夏的 spring的依赖注入是什么意思,侵删! Spring 能有效地组织J2EE应用各层的对象.不管是 ...

  6. SpringBoot系列: 理解 Spring 的依赖注入(一)

    ==============================Spring 的依赖注入==============================对于 Spring 程序, Spring 框架为我们提供 ...

  7. Spring.NET依赖注入框架学习--实例化容器常用方法

    Spring.NET依赖注入框架学习---实例化容器常用方法 本篇学习实例化Spring.NET容器的俩种方式 1.通过XmlObjectFactory创建一个Spring.NET容器 IResour ...

  8. Spring.NET依赖注入框架学习--简单对象注入

    Spring.NET依赖注入框架学习--简单对象注入 在前面的俩篇中讲解了依赖注入的概念以及Spring.NET框架的核心模块介绍,今天就要看看怎么来使用Spring.NET实现一个简单的对象注入 常 ...

  9. Spring.NET依赖注入框架学习--简介

    Spring.NET依赖注入框架学习--Spring.NET简介 概述 Spring.NET是一个应用程序框架,其目的是协助开发人员创建企业级的.NET应用程序.它提供了很多方面的功能,比如依赖注入. ...

  10. Spring.NET依赖注入框架学习--入门

    Spring.NET依赖注入框架学习--入门 在学些Spring.net框架之前,有必要先脑补一点知识,比如什么是依赖注入?IOC又是什么?控制反转又是什么意思?它们与Spring.net又有什么关系 ...

随机推荐

  1. 2022-04-08:在一张 无向 图上,节点编号0~N-1。老鼠开始在1节点,猫在2节点,0号节点是洞,老鼠想进洞, 老鼠第先出发,猫后出发,轮流行动。 在每个玩家的行动中,他们 必须 沿着图中与所

    2022-04-08:在一张 无向 图上,节点编号0~N-1.老鼠开始在1节点,猫在2节点,0号节点是洞,老鼠想进洞, 老鼠第先出发,猫后出发,轮流行动. 在每个玩家的行动中,他们 必须 沿着图中与所 ...

  2. pycharm-professional-2023 下载安装

    PyCharm Professional 是一款针对 Python 编程的集成开发环境 (IDE),由 JetBrains 公司开发和维护.它是 PyCharm 社区版的升级版,提供了更多的功能和工具 ...

  3. 1406, "Data too long for column 'od_seq' at row 1"

    问题描述:1406, "Data too long for column 'od_seq' at row 1" 问题分析:录入数据长度超出字段的最大限制 解决方法:增加max_le ...

  4. AcWing901. 滑雪(python)

    题目详情 知识点 记忆化DP 思路 自己的思路(仅参考):一开始想的是找最大值,然后从最大值开始向下滑,但是我们是要求最长路径,不一定是从最高的点滑下去的,也不一定是滑到最低点,而且会存在最大值不止一 ...

  5. C++面试八股文:C++中,设计一个类要注意哪些东西?

    某日二师兄参加XXX科技公司的C++工程师开发岗位第9面: 面试官:C++中,设计一个类要注意哪些东西? 二师兄:设计一个类主要考虑以下几个方面:1.面向对象的封装.继承及多态.2.big three ...

  6. Qt+QtWebApp开发笔记(五):http服务器html中使用json触发ajax与后台交互实现数据更新传递

    前言   前面完成了页面的跳转.登录,很多时候不刷新页面就想刷新局部数据,此时ajax就是此种技术,且是异步的.  本篇实现网页内部使用js调用ajax实现异步交互数据.  在js中使用 ajax是通 ...

  7. Nanoframework 操作单片机蓝牙配置WIFI的案例

    Nanoframework 操作单片机蓝牙配置WIFI的案例 通过Nanoframework的蓝牙配置Wifi的名称和密码 下面是基本需要的工具 ESP32设备一个 需要支持蓝牙和wifi,一般情况的 ...

  8. boot 项目启动:Error starting ApplicationContext. To display the conditions report re-run

    Error starting ApplicationContext. To display the conditions report re-run 问题描述 boot 工程启动不了 原因分析: 以后 ...

  9. sql server注入rce实践

    背景:在漏洞挖掘中,合理的利用sql注入,可以把注入转换成rce,使一个高危漏洞变成严重漏洞.在红蓝对抗中,利用注入rce,实现内网横向移动.笔者基于漏洞挖掘和红蓝对抗上遇到的sql server注入 ...

  10. 把jar包打成docker镜像并推送到Docker Hub

    1.准备需要的jar包并复制到服务器某个目录下 2.在此目录下,创建Dockerfile的文本文件,并将以下内容添加到文件中: # 基础镜像 FROM openjdk:8-jre # author(可 ...