Spring
  BbWWsUV3fzWQ 2023年11月01日 53 0

1、Spring

1.1、简介

  • spring :春天———>给软件行业带来了春天!

  • 2002,首次退出Springkuang框架雏形,interface21框架!

  • spring 框架即以interface21框架为基础,经过重新设计,不断丰富其内涵,于2004年3月24日发布1.0版本。

  • Rod Johnson,Spring Framework创始人,Java和J2EE开发领域的专家。很难以想象,悉尼大学的音乐学博士,然而他的专业不是计算机,而是音乐学。

  • spring 理念: 使现有的技术更加容易使用,本身是一个大杂烩,整合了现有的技术框架!

  • SSH ; Struct2 + spring + Hibernate!

  • SSM : springmvc + spring + mybatis

官网文档 Spring Framework Documentation

历史文档 Index of /spring-framework/docs

官网接口 Overview (Spring Framework 5.2.24.RELEASE API)

下载地址 http://repo.spring.io/release/org/springframework/spring

​ github github.com

											经典版本4.3.9
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.2.9.RELEASE</version>
</dependency>

1.2、优点

  • spring是一个免费的开源的容器【框架】
  • spring是一个轻量级非入侵式的框架 不会对原来的项目产生影响
  • 控制反转(IOC),面相切面编程(AOP)
  • 支持事务处理,对框架整合的支持

总结一点:spring就是一个轻量级的控制反转(IOC)和面向切面(AOP)编程的框架

1.3、组成

img

1.4、拓展

spring官网介绍:现代化的java开发!说白了就是基于spring的开发!

img

  • Spring Boot

    • 一个快速开发的脚手架
    • 基于SpringBoot可以快速的开发单个微服务
    • 约定大于配置!
  • Spring Cloud

    • Spring Cloud 是基于Spring Boot实现的

因为现在大多数公司都在使用Spring Boot 进行快速开发, 学习Spring Boot 的前提,需要完全掌握Spring以及SpringMVC!承上启下

弊端 : 发展太久后违背了原来的理念! 配置十分繁琐,人称 “配置地狱”

2、IOC理论推导

  1. UserDao 接口
    1.
  2. UserDaoImpl 实现类
    1.
  3. UserService 业务接口
    1.
  4. UserServiceImpl 业务实现类
    1.

在我们之前的业务中 , 用户的需求可能会影响我们原来的代码,我们需要根据用户的需求去修改源码! 如果程序代码量非常大,修改一次的成本十分昂贵!

我们使用一个set接口实现已经发生了革命性变化

private UserDao userDao;
// 利用set 进行动态实现值的注入
public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
}
  • 之前,程序是主动创建对象!控制权在程序员手上
  • 使用了set注入之后,程序员不再具有主动性,而是变成了被动接受对象!

这个思想,从本质上解决了问题,我们程序员不再去管理对象的创建了。系统的耦合性大大降低,可以更加专注的在业务层的实现上,这就是IOC 的原型!

img

ioc本质

控制反转IOC (Inversion of Control) , 是一种设计思想,DI(依赖注入)是实现IOC的一种方法,也有人认为DI 只是IOC的另一种说法。没有IOC的程序中,我们使用面相对象编程,对象的创建与对象间的依赖关系完全硬编码在程序中,对象的创建由程序自己控制,控制反转后将对象的创建移交给第三方,个人认为所谓控制反转就是:获得依赖对象的方式反转了。

采用 XML 方式配置bean的时候,bean的定义信息和实现分离的,而采用注解的方式可以把两者合为一体,bean的定义信息直接以注解的形式定义在实现类中,从而达到了零配置的目的。

控制反转是一种通过描述(XML或注解)并通过第三方去产生或获取特定对象的方式。在Spring中实现控制反转的就是IOC容器,其实现方法是依赖注入(Dependency injection,DI)。

img

IoC是Spring框架的核心内容,使用多种方式完美的实现了IoC,可以使用XML配置,也可以使用注解,新版本的Spring也可以零配置实现IoC。

Spring容器在初始化时先读取配置文件,根据配置文件或元数据创建与组织对象存入容器中,程序使用时再从Ioc容器中取出需要的对象。

3、HelloSpring

3.1、导入jar包

注 : spring 需要导入commons-logging进行日志记录 . 我们利用maven , 他会自动下载对应的依赖项 .

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>5.2.0.RELEASE</version>
</dependency>

3.2、编写代码

1、编写一个Hello实体类

public class Hello {
   private String name;

   public String getName() {
       return name;
  }
   public void setName(String name) {
       this.name = name;
  }

   public void show(){
       System.out.println("Hello,"+ name );
  }
}

2、编写我们的spring文件 , 这里我们命名为beans.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就是java对象 , 由Spring创建和管理-->
   <bean id="hello" class="com.kuang.pojo.Hello">
       <property name="name" value="Spring"/>
   </bean>
</beans>

3、我们可以去进行测试了 .

@Test
public void test(){
   //解析beans.xml文件 , 生成管理相应的Bean对象
   ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
   //getBean : 参数即为spring配置文件中bean的id .
   Hello hello = (Hello) context.getBean("hello");
   hello.show();
}

3.3、思考

  • Hello 对象是谁创建的 ? 【hello 对象是由Spring创建的
  • Hello 对象的属性是怎么设置的 ? hello 对象的属性是由Spring容器设置的

这个过程就叫控制反转 :

  • 控制 : 谁来控制对象的创建 , 传统应用程序的对象是由程序本身控制创建的 , 使用Spring后 , 对象是由Spring来创建的
  • 反转 : 程序本身不创建对象 , 而变成被动的接收对象 .

依赖注入 : 就是利用set方法来进行注入的.

IOC是一种编程思想,由主动的编程变成被动的接收

可以通过newClassPathXmlApplicationContext去浏览一下底层源码 .

3.4、修改案例一

我们在案例一中, 新增一个Spring配置文件beans.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 id="MysqlImpl" class="com.kuang.dao.impl.UserDaoMySqlImpl"/>
   <bean id="OracleImpl" class="com.kuang.dao.impl.UserDaoOracleImpl"/>

   <bean id="ServiceImpl" class="com.kuang.service.impl.UserServiceImpl">
       <!--注意: 这里的name并不是属性 , 而是set方法后面的那部分 , 首字母小写-->
       <!--引用另外一个bean , 不是用value 而是用 ref-->
       <property name="userDao" ref="OracleImpl"/><!--具体使用哪个接口这里可以直接配置-->
   </bean>

</beans>

测试!

@Test
public void test2(){
   ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
   UserServiceImpl serviceImpl = (UserServiceImpl) context.getBean("ServiceImpl");//这里相当于将原来的Service层也IOC了,不需要再在代码中写出调用哪个接口,只需要在配置文件中指明调用的接口即可。
   serviceImpl.getUser();
    //原来的步骤
    //UserService userService = new UserServiceImpl();
    //userService.setUserDao(new UserDaoMysqlImpl());//原先需要在代码中调用特定的方法
	//userService.getUser();
}

OK , 到了现在 , 我们彻底不用再程序中去改动了 , 要实现不同的操作 , 只需要在xml配置文件中进行修改 , 所谓的IoC,一句话搞定 : 对象由Spring 来创建 , 管理 , 装配 !

思考问题:

  • Hello 对向是谁创建的?

  • Hello 对象是由Spring 创建的

  • Hello 对象的属性是怎么设置的?

  • hello 对象的属性是spring容器设置

4、IOC 创建对象的方式

  1. 使用无参构造创建对象,默认!

  2. 假设我们要使用有参构造创建对象。

    1. 下标赋值

              <!--    下标赋值     -->
      <bean id="user" class="com.lmq.pojo.User">
          <constructor-arg index="0" value="000"/>
      </bean>
      
    2. 类型赋值

              <!--  2(不建议使用)  通过类型创建   基本类型直接用  引用类型全名   -->
      <bean id="user" class="com.lmq.pojo.User">
          <constructor-arg value="111" type="java.lang.String"/>
      </bean>
      
    3. 参数名 重点掌握

          <!--  3 直接通过参数名来设置  -->
      <bean id="user" class="com.lmq.pojo.User">
          <constructor-arg name="name" value="333"/>
      </bean>
      

总结: 在配置文件加载的时候,容器中管理的对象就已经初始化了

5、Spring配置

5.1、 别名

    <!-- 别名 -->
    <alias name="user" alias="userNew"/>

5.2、 Bean的配置

<!--
    id    : nean 的唯一标识符,也就是相当于我们学的对象名
    class : bean 对象所对应的全 限定名 : 包名 + 类型
    name  : 也是别名,而且name 可以取多个别名 逗号分割等
-->
<bean id="userT" class="com.lmq.pojo.UserT" name="t,userT2">

5.3、import

import 一般用于团队开发使用, 他可以将多个配置文件导入合并为一个,

假设,现在项目中有多个人开发 这三个人负责不同的类开发 不同的类要注册在不同的bean中

我们可以使用import将所有人的合并为一个总的

  • 张三
  • 李四
  • 王五
  • applicationContext
<?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">
    <import resource="beans.xml"/>
    <import resource="beans2.xml"/>
    <import resource="beans3.xml"/>
</beans>

内容相同也会合并

6、DI 依赖注入

6.1、构造器注入

前面已经使用

6.2、set方式注入【重点】

  • 依赖注入:Set注入!
    • 依赖; bean对象的创建依赖于容器
    • 注入:bean对象的所有属性,由容器来注入

【环境搭建】

  1. 复杂类型

    public class Address {
        private String address;
    
        @Override
        public String toString() {
            return "Address{" +
                    "address='" + address + '\'' +
                    '}';
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    }
    
  2. 真实测试对象

    @Data
    public class Student {
        private String name;
        private Address address;
        private String[] books;
        private List<String> hobbys;
        private Map<String,String> card;
        private Set<String> games;
        private String wife;
        private Properties info;
    }
    
  3. beans.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 id="student" class="com.lmq.pojo.Student">
            <property name="name" value="lmq"/>
        </bean>
    </beans>
    
  4. 测试类

    import com.lmq.pojo.Student;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/23 22:00
     */
    public class MyTest {
        public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
            Student student = (Student) context.getBean("student");
            System.out.println(student.getName());
        }
    }
    
    
  5. 完善注入信息

    <?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 id="address" class="com.lmq.pojo.Address">
            <property name="address" value="湖北"/>
        </bean>
    
        <bean id="student" class="com.lmq.pojo.Student">
            <!--  第一种 普通注入,value      -->
            <property name="name" value="lmq"/>
    
            <!-- 第二种 bean注入 ref -->
            <property name="address" ref="address"/>
            <!-- 第三种 数组注入 -->
            <property name="books">
                <array>
                    <value>三国演义</value>
                    <value>西游记</value>
                    <value>水浒传</value>
                    <value>红楼梦</value>
                </array>
            </property>
            <!-- 第四种 List -->
            <property name="hobbys">
                <list>
                    <value>骑单车</value>
                    <value>学习</value>
                    <value>看电视</value>
                </list>
            </property>
    
            <!-- map -->
            <property name="card">
                <map>
                    <entry key="身份证" value="1234546123456781234"/>
                    <entry key="银行卡" value="12345612347561234"/>
                    <entry key="学生卡" value="123789123789"/>
                </map>
            </property>
            <!-- set -->
            <property name="games">
                <set>
                    <value>LOL</value>
                    <value>COC</value>
                    <value>BOB</value>
                </set>
            </property>
            <!-- 空值注入 -->
            <property name="wife">
                <null/>
            </property>
            <!-- Property -->
            <property name="info">
                <props>
                    <prop key="学号">123456789</prop>
                    <prop key="url">男</prop>
                    <prop key="name">123</prop>
                    <prop key="pwd">123</prop>
                </props>
    
            </property>
    
    
        </bean>
    
    </beans>
    

6.3、拓展方式注入

我们可以使用p命名空间和c命名空间进行注入

官方解释

image-20230623231201438

<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"
       xmlns:c="http://www.springframework.org/schema/c"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd">
    <!-- p命名空间注入 可以直接注入简单属性的值: >>  property-->
    <bean id="user" class="com.lmq.pojo.User" p:name="小米" p:age="18"/>
    <!-- c命名空间注入 通过构造器注入:construct-args-->
    <bean id="user2" class="com.lmq.pojo.User" c:name="大米" c:age="20"/>
</beans>

测试:

@Test
public void Testlmq(){
    ApplicationContext context = new ClassPathXmlApplicationContext("userbeans.xml");
    User user =  context.getBean("user2", User.class);
    System.out.println(user.toString());
}

注意点: p命名空间和c命名空间不能直接使用,需要导入

xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"

6.4、bean的作用域

scopes 作用域

Scope Description
singleton (Default) Scopes a single bean definition to a single object instance for each Spring IoC container.
prototype Scopes a single bean definition to any number of object instances.
request Scopes a single bean definition to the lifecycle of a single HTTP request. That is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
session Scopes a single bean definition to the lifecycle of an HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.
application Scopes a single bean definition to the lifecycle of a ServletContext. Only valid in the context of a web-aware Spring ApplicationContext.
websocket Scopes a single bean definition to the lifecycle of a WebSocket. Only valid in the context of a web-aware Spring ApplicationContext.
  1. 单例模式(singleton 默认机制)

       <bean id="user2" class="com.lmq.pojo.User" c:name="大米" c:age="20" scope="singleton"/>
    

    singleton

  2. prototype原型模式:每次从容器中get的时候都会产生一个新对象

    <bean id="user2" class="com.lmq.pojo.User" c:name="大米" c:age="20" scope="prototype"/>
    

    prototype

  3. 其余的request、session、application、这些个只能在web中开发使用

7、bean的自动装配

  • 自动装配是Spring满足bean依赖一种方式!
  • Spring会在上下文自动寻找,并自动给bean装配属性!

在spring中有三种装配的方式

  1. 在xml中显示的配置
  2. 在java中显示配置
  3. 隐式的自动装配bean 【重要】、

7.1、 测试

  1. 环境搭建
    • 一个人有两个宠物
    • 三个类 人 动物1 动物2
    • 装配到beans
    • 测试

7.2、 ByName自动装配

<!--
        byName:会自动在容器上下文中查找和自己对象set 方法后面的值对应的 beanid!
        byType:会自动在容器上下文中查找和自己对象属性类型相同的bean!
-->
<bean id="people" class="com.lmq.pojo.People" p:name="小刘" autowire="byName"/>

7.3、 ByType自动装配

<bean class="com.lmq.pojo.Cat"/>
<bean class="com.lmq.pojo.Dog"/>

<bean id="people" class="com.lmq.pojo.People" p:name="小刘" autowire="byType"/>

小结

  • byName的时候,需要保证所有bean的id唯一,并且这个bean需要和自动注入的属性的方法的值一致!
  • byType的时候,需要保证所有bean的class唯一,并且这个bean需要和自动注入的属性的类型一致!

7.4、使用注解实现自动装配

jdk1.5支持的注解 spring2.5支持注解

The introduction of annotation-based configuration raised the question of whether this approach is “better” than XML.

要使用注解须知:

  1. 导入约束 context约束

    xmlns:context="http://www.springframework.org/schema/context"

  2. 配置注解的支持:context:annotation-config/

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

@Autowired

直接在属性上使用 使用后可以忽略set方法!也可以在set方法上使用

使用Autowired我们可以不写set方法了,青提是你这个自动装配的属性在IOC(spring) 容器中存在,且符合名字byName!

科普:

@Nullable   //字段标记了这个注解 说明这个字段可以为null 在set传参前使用

@Autowrired(required = false)  //如果定义了Autowired的required属性为false,说明这个对象可以为null 否则不能为空

组合使用: 环境比较复杂 无法通过一个注解@Autowired完成时可以使用@Qualifier(value = "dog222")

package com.lmq.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * @author 羡鱼
 * @version 1.0
 * @date 2023/6/23 23:53
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class People {
    @Autowired
    public Cat cat;
    @Autowired
    @Qualifier(value = "dog222")
    private Dog dog;
    private String name;
}

@Resource注解

@Data
@AllArgsConstructor
@NoArgsConstructor
public class People {
    @Resource
    public Cat cat;
    @Resource(name = "dog222")
    private Dog dog;
    private String name;
}

小结:

@Resource 和 Autowired 的区别:

  • 都是用来自动装配的,都可以放在属性字段上
  • @Autowired通过byType的方式实现 而且必须要求这个对象存在 【常用】
  • @Resource默认通过byName的方式实现,如果找不到名字,则通过byType实现 如果两个都找不到就报错!【常用】
  • 执行顺序不同 @Autowired通过byType的方式实现,@Resource默认通过byName的方式实现。

8、使用注解开发

spring 4 之后,要是有注解开发 不能没有aop包

img

使用注解需要导入context约束,增加注解的支持

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

    <context:annotation-config/>

</beans>
  1. bean

  2. 属性如何注入

    @Component
    public class User {
        public String lmq = "小刘";
        //相当于  <property name="name" value="666"/>
        @Value("666")
        public String name;
    
    }
    
  3. 衍生的注解

    @Component 有几个衍生注解,我们在web开发中,会按照MVC三层架构分成!

    • dao 【@Repository】

    • service 【@Service】

    • controller 【@Controller】

      这四个注解功能都一样,代表将某个类注入到Spring中,装配Bean

  4. 自动装配配置

    - @Autowired: 自动装配通过类型。名字
    		如果Autowired不能为一自动装配上属性,则需要通过@Qualifier(value="xxx")
    - @Nullable   字段标记了这个注解,说明这个字段可以为null
    - @Resource   自动装配通过名字,类型。  java原生
    
  5. 作用域

    @Scope

    @Component
    @Scope("prototype")
    public class User {
        public String lmq = "小刘";
        //相当于  <property name="name" value="666"/>
        @Value("666")
        public String name;
    
    }
    
  6. 小结

    xml域注解

    • xml 更加万能,适用于任何场合! 维护非常方便
    • 注解,不是自己的类使用不了,维护相对复杂

    xml与注解最佳实践

    • xml用来管理bean;

    • 注解只负责完成属性的注入

    • 我们在使用的过程中,只需要注意一个问题:必须让注解生效,就需要开启注解的支持

      <!--指定扫描的包,这个包下的注解就会生效-->
      <context:component-scan base-package="com.lmq"/>
      <context:annotation-config/>
      

9、使用java的方式配置Spring

我们现在要完全不使用spring的xml配置了,全权交给java来做

JavaConfig 是spring的一个子项目,在spring4之后,它成为了一个核心功能

img

实体类

@Data
// 这个注解的意思就是这个类被spring接管了  注册到容器中
@Component
public class User {
    @Value("hello")
    private String name;
}

配置文件

@Configuration
@ComponentScan("com.lmq.pojo")
@Import(lmq.class)
public class config {
    //注册一个bean  相当于我们之前写的一个bean标签
    //这个方法的名字,就相当于bean标签的id属性
    // 这个方法的返回值类型 就相当于bean标签的class属性
    @Bean
    public User user001(){
        return new User();  // 返回的就是要注入到bean的对象;
    }
}

测试类

public class MyTest {
    // 如果完全使用了配置方式去做,我们只能通过AnnotationConfig上下文来获取容器,通过配置类的class对象加载!
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(config .class);
        User getuser = context.getBean("user001", User.class);
        System.out.println(getuser.getName());
    }
}

纯java的配置方式,在SpringBoot中随处可见!

10、代理模式

为什么要学习代理模式?因为这就是SpringAOP的底层! 【SpringAop 和 SpringMVC】

代理模式的分类:

静态代理

动态代理

img

10.1、静态代理

角色分析:

  • 抽象角色:一般会使用接口或者抽象类累解决
  • 真实角色:被代理的角色
  • 代理角色:代理真实角色,代理真实角色后,我们一般会做一些附属操作
  • 客户: 访问代理对象的人

代码步骤:

  1. 接口

    package com.lmq.demo01;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/24 15:24
     */
    //租房
    public interface Rent {
        public void rent();
    }
    
    
  2. 真实角色

    package com.lmq.demo01;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/24 15:24
     */
    //房东
    public class Host implements Rent {
        @Override
        public void rent() {
            System.out.println("出租房子");
        }
    }
    
  3. 代理角色

    package com.lmq.demo01;
    
    import lombok.AllArgsConstructor;
    import lombok.NoArgsConstructor;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/24 15:28
     */
    //多用组合少用继承
    public class Proxy {
        private Host host;
        public Proxy(){
    
        }
        public Proxy(Host host){
            this.host = host;
        }
        public void rent(){
            seeHouse();
            host.rent();
            hetong();
            fare();
        }
    
        public void seeHouse(){
            System.out.println("中介带你看房子");
        }
        public void hetong(){
            System.out.println("签租赁合同");
        }
        public void fare(){
            System.out.println("收中介费");
        }
    
    }
    
    
  4. 客户端访问代理角色

    package com.lmq.demo01;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/24 15:25
     */
    public class Client {
        public static void main(String[] args) {
            // 房东要租房子
            Host host = new Host();
            //代理,中介帮房东租房子,但是呢?代理角色一般会有一些附属操作
            Proxy proxy = new Proxy(host);
            // 不用找房东,直接找中介
            proxy.rent();
        }
    }
    
    

代理模式的好处:

  • 可以使真实角色的操作更加纯粹!不用去关注一些公共业务
  • 公共业务交给代理角色!实现业务的分工!
  • 公共业务发送拓展的时候方便集中管理!

缺点:

  • 一个真实角色会产生一个代理角色;代码量翻倍。开发效率降低

不改变原有代码面相对象七大原则

10.2、加深理解

代码:对应08-demo02

聊聊AOP

img

10.3、动态代理

  • 动态代理和静态代理角色一样
  • 动态代理的代理类是动态生成的,不是我们直接写好的
  • 动态代理也分为两大类; 基于接口的抽象类 基于类的动态电路
    • 基于接口—jdk的动态代理 【学习原生的】
    • 基于类: cglib
    • java字节码:javasistjavassist详解

需要了解两个类 Proxy : 代理 InvocationHandler : 调用处理程序

InvocationHandler 调用处理程序并且返回结果

Prox 提供创建动态代理的

动态代理的好处:

  • 可以使真实角色的操作更加纯粹!不用去关注一些公共业务
  • 公共业务交给代理角色!实现业务的分工!
  • 公共业务发送拓展的时候方便集中管理!
  • 一个动态代理类代理的是一个接口,一般就是对应的一类业务
  • 一个动态代理类可以代理多个类,只要实现同一个接口

11、AOP

11.1、什么是AOP

AOP(Aspect Oriented Programming)意为:面相切面编程,通过与编译的方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,也是Spring框架中的一个重要内容,是函数式编程的一种衍生泛型。利用AOP可以对业务逻辑各各部分进行隔离,从而是得业务逻辑部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。

img

11.2、AOP在Spring中的作用

提供声明事务;允许用户自定义切面

  • 横切关注点:跨越应用程序多个模块的方法或功能 。即是,与我们业务逻辑无关的,但是我们需要关注的部分,就是横切关注点。如日志,安全,缓存,事务等等。。。
  • 切面(ASPECT):横切关注点 被模块化的特殊对象。即,它是一个类
  • 通知(Advice): 切面必须完成的工作。即类中的一个方法。
  • 目标(Target): 被通知对象。
  • 代理(Proxy): 向目标对象应用停止之后创建的对象。
  • 切入点(PointCut): 切面通知执行的“地点”的定义。
  • 连接点(Joinpoint): 与切入点匹配的执行点。

img

SpringAOP中,通过Advice定义横切逻辑,Spring中支持5种类型的Advice:

img

即在AOP不改变原有代码的情况下,去增加新的功能。

11.3、使用Spring实现AOP

【重点】 使用AOP织入,需要导入一个依赖包

<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.9.6</version>
    <scope>runtime</scope>
</dependency>

方式一:使用Spring的API接口 【主要SpringAPI接口实现】

<!--  方式一:使用原生Spring API接口  -->
<aop:config>
    <!--    切入点  expression表达式 =》 execution(要执行的!×××××××)   -->
    <aop:pointcut id="pointcut" expression="execution(* com.lmq.service.UserSerciceImpl.*(..))"/>

<!--   执行环绕增强    -->
    <aop:advisor advice-ref="log" pointcut-ref="pointcut"/>
    <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
</aop:config>

方式二:自定义类实现AOP 【主要是切面定义】

<bean class="com.lmq.diy.DiyPointCut" id="diy"/>
<aop:config>
    <!--    自定义切面    -->
    <aop:aspect ref="diy">
        <!-- 切入点 -->
        <aop:pointcut id="point" expression="execution(* com.lmq.service.UserSerciceImpl.*(..))"/>
        <!-- 通知 -->
        <aop:before method="before" pointcut-ref="point"/>
        <aop:after method="after" pointcut-ref="point"/>
    </aop:aspect>
</aop:config>

方式三:使用注解实现!

package com.lmq.diy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * @author 羡鱼
 * @version 1.0
 * @date 2023/6/25 0:18
 */
// 方式三: 使用注解方式实现AOP

@Aspect   //标注一个切面
public class AnnotationPointCut {
    @Before("execution(* com.lmq.service.UserSerciceImpl.*(..))")
    public void before(){
        System.out.println("=======方法前=======");
    }
    @After("execution(* com.lmq.service.UserSerciceImpl.*(..))")
    public void after(){
        System.out.println("=======方法后=======");
    }
    //在环绕增强中,我们可以给定一个参数,代表我们要获取处理的切入的点:
    @Around("execution(* com.lmq.service.UserSerciceImpl.*(..))")
    public void around(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("=======环绕前=======");
        // 执行方法
        Signature signature = jp.getSignature();// 获得签名   类的信息
        Object proceed = jp.proceed();  //执行方法

        System.out.println("=======环绕后=======");
        System.out.println(signature);
        System.out.println(proceed);

    }
}

    <bean id="annotationPointCut" class="com.lmq.diy.AnnotationPointCut"/>
<!--  开启注解支持  JDK(默认)expose-proxy="false"   cglib -->
    <aop:aspectj-autoproxy expose-proxy="true"/>

12、整合mybatis

步骤:

  1. 导入jar包

    • junit
    • mybatis
    • mysql数据库
    • spring相关
    • aop织入
    • mybatis-spring 【new】
    • <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <parent>
              <groupId>com.lmq</groupId>
              <artifactId>spring</artifactId>
              <version>1.0-SNAPSHOT</version>
          </parent>
      
          <artifactId>spring-10-mybatis</artifactId>
      
          <properties>
              <maven.compiler.source>8</maven.compiler.source>
              <maven.compiler.target>8</maven.compiler.target>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
      
          <dependencies>
              <!--    单元测试    -->
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.12-beta-3</version>
                  <scope>test</scope>
              </dependency>
              <!--mysql链接-->
              <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <version>8.0.28</version>
              </dependency>
              <!--        导入mybatis-->
              <dependency>
                  <groupId>org.mybatis</groupId>
                  <artifactId>mybatis</artifactId>
                  <version>3.5.2</version>
              </dependency>
              <!--        spring-->
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-webmvc</artifactId>
                  <version>5.2.9.RELEASE</version>
              </dependency>
              <!--        Spring 操作数据库-->
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-jdbc</artifactId>
                  <version>5.2.9.RELEASE</version>
              </dependency>
              <!--        AOP织入-->
              <dependency>
                  <groupId>org.aspectj</groupId>
                  <artifactId>aspectjweaver</artifactId>
                  <version>1.9.6</version>
              </dependency>
              <!--        mybatis 与spring 整合-->
              <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
              <dependency>
                  <groupId>org.mybatis</groupId>
                  <artifactId>mybatis-spring</artifactId>
                  <version>2.0.6</version>
              </dependency>
              <dependency>
                  <groupId>org.projectlombok</groupId>
                  <artifactId>lombok</artifactId>
                  <version>1.18.24</version>
              </dependency>
      
          </dependencies>
      
      
          <build>
              <resources>
                  <resource>
                      <directory>src/main/java</directory>
                      <includes>
                          <include>**/*.properties</include>
                          <include>**/*.xml</include>
                      </includes>
                      <filtering>false</filtering>
                  </resource>
                  <resource>
                      <directory>src/main/resources</directory>
                      <includes>
                          <include>**/*.properties</include>
                          <include>**/*.xml</include>
                      </includes>
                      <filtering>false</filtering>
                  </resource>
              </resources>
          </build>
      </project>
      
  2. 编写配置文件

    mybatis-config.xml
    
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "https://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    <!--    包的别名-->
        <typeAliases>
            <package name="com.lmq.pojo"/>
        </typeAliases>
    </configuration>
    
    spring-dao.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">
    
    <!--DataSource: 使用Spring数据源替换Mybatyis的配置  c3p0 dbcp druid
        我们这里使用Spring提供的JDBC : org.springframework.jdbc.datasource.DriverManagerDataSource
    -->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://124.71.168.125:3310/mybatis?useSSL=true&amp;userUnicode=true&amp;characterEncoding=UTF-8"/>
            <property name="username" value="root"/>
            <property name="password" value="123456"/>
        </bean>
    <!--sqlSessionFactory-->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <!-- 绑定mybatis -->
            <property name="configLocation" value="classpath:mybatis-config.xml"/>
            <property name="mapperLocations" value="classpath:com/lmq/mapper/*.xml"/>
            <!-- mybatis-config.xml 文件的配置 -->
        </bean>
    <!--SqlSessionTemplate 就是我们使用的sqlsession    -->
        <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <!--   只能用构造器注入sqlSessionFactory  因为没有set方法   -->
            <constructor-arg index="0" ref="sqlSessionFactory"/>
        </bean>
    
    <!--    <bean class="com.lmq.mapper.UserMapperImpl" id="userMapper">-->
    <!--        <property name="sqlSession" ref="sqlSession"/>-->
    <!--    </bean>-->
    </beans>
    
    applicationContext.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">
    
        <import resource="spring-dao.xml"/>
    
        <bean class="com.lmq.mapper.UserMapperImpl" id="userMapper">
            <property name="sqlSession" ref="sqlSession"/>
        </bean>
        <bean id="userMapper2" class="com.lmq.mapper.UserMapperImpl2">
            <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
        </bean>
    </beans>
    
  3. 测试

    import com.lmq.mapper.UserMapper;
    import com.lmq.pojo.User;
    import lombok.ToString;
    import org.apache.ibatis.io.Resources;
    import org.apache.ibatis.session.SqlSession;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.apache.ibatis.session.SqlSessionFactoryBuilder;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.List;
    
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/25 1:04
     */
    public class MyTest {
        @Test
        public void test() throws IOException {
            String resources = "mybatis-config.xml";
            InputStream in = Resources.getResourceAsStream(resources);
    
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(in);
            SqlSession sqlSession = sessionFactory.openSession(true);
    
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            List<User> users = mapper.selectUser();
            for (User user : users) {
                System.out.println(user);
            }
            sqlSession.close();
    
        }
    
        @Test
        public void test2(){
            ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
            UserMapper userMapper = context.getBean("userMapper", UserMapper.class);
            for (User user : userMapper.selectUser()) {
                System.out.println(user);
            }
        }
        @Test
        public void test3(){
            ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
            UserMapper userMapper = context.getBean("userMapper2", UserMapper.class);
            for (User user : userMapper.selectUser()) {
                System.out.println(user);
            }
        }
    }
    
    

12.1、mybatis 【资源过滤问题】

  1. 编写实体类

    User.class

    package com.lmq.pojo;
    
    import lombok.Data;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/25 0:54
     */
    @Data
    public class User {
        private int id;
        private String name;
        private String pwd;
    }
    
    
  2. 编写核心配置文件

    mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "https://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    <!--    包的别名-->
        <typeAliases>
            <package name="com.lmq.pojo"/>
        </typeAliases>
    
    <!--    <environments default="development">-->
    <!--        <environment id="development">-->
    <!--            <transactionManager type="JDBC"/>-->
    <!--            <dataSource type="POOLED">-->
    <!--                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>-->
    <!--                <property name="url" value="jdbc:mysql://124.71.168.125:3310/mybatis?useSSL=true&amp;userUnicode=true&amp;characterEncoding=UTF-8"/>-->
    <!--                <property name="username" value="root"/>-->
    <!--                <property name="password" value="123456"/>-->
    <!--            </dataSource>-->
    <!--        </environment>-->
    <!--    </environments>-->
    <!--    <mappers>-->
    <!--        <mapper resource="com/lmq/mapper/UserMapper.xml"/>-->
    <!--&lt;!&ndash;        <mapper class="com.lmq.mapper.UserMapper"/>&ndash;&gt;-->
    <!--    </mappers>-->
    </configuration>
    
  3. 编写接口

    UserMapper.class

    package com.lmq.mapper;
    
    import com.lmq.pojo.User;
    
    import java.util.List;
    
    /**
     * @author 羡鱼
     * @version 1.0
     * @date 2023/6/25 0:58
     */
    public interface UserMapper {
        public List<User> selectUser();
    }
    
    
  4. 编写mapper.xml

    UserMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
            "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.lmq.mapper.UserMapper">
        <select id="selectUser" resultType="user">
            select * from mybatis.user
        </select>
    </mapper>
    
  5. 测试

    @Test
    public void test() throws IOException {
        String resources = "mybatis-config.xml";
        InputStream in = Resources.getResourceAsStream(resources);
    
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(in);
        SqlSession sqlSession = sessionFactory.openSession(true);
    
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = mapper.selectUser();
        for (User user : users) {
            System.out.println(user);
        }
        sqlSession.close();
    
    }
    

资源过滤 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.lmq</groupId>
        <artifactId>spring</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>spring-10-mybatis</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!--    单元测试    -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12-beta-3</version>
            <scope>test</scope>
        </dependency>
        <!--mysql链接-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.28</version>
        </dependency>
        <!--        导入mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.2</version>
        </dependency>
        <!--        spring-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.9.RELEASE</version>
        </dependency>
        <!--        Spring 操作数据库-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.2.9.RELEASE</version>
        </dependency>
        <!--        AOP织入-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.6</version>
        </dependency>
        <!--        mybatis 与spring 整合-->
        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
        </dependency>

    </dependencies>


    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>
</project>

12.2、Mybatis-Spring

MyBatis-Spring MyBatis Spring Framework Spring Batch Java
3.0 3.5+ 6.0+ 5.0+ Java 17+
2.1 3.5+ 5.x 4.x Java 8+
2.0 3.5+ 5.x 4.x Java 8+
1.3 3.4+ 3.2.2+ 2.1+ Java 6+
  1. 编写数据源
  2. sqlSessionFactory
  3. sqlSessionTemplate =》 Mybatis的 sqlSession
  4. 要给接口加实现类
  5. 将自己写的实现类,注入到Spring中

13、声明式事务

13.1、回顾事务

  • 把一组业务当成一个业务来做;要么都成功,要么都失败!
  • 事务在项目开发中,十分的重要,涉及到数据的一致性,不能马虎!
  • 确保完整性和一致性;

事务ACID原则:

  • 原子性
  • 一致性
  • 隔离性
    • 多个业务可能操作同一个资源,防止数据损坏
  • 持久性
    • 事务一旦提交,无论系统发生什么问题,结果都不会被影响,被持久化的写到存储器中!

13.2、spring中的事务管理

  • 声明式事务: AOP

    <!--  配置声明式事务  -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <constructor-arg ref="dataSource" />
        </bean>
    <!-- 结合AOP执行事务的织入   -->
    <!--  配置事务的类   配置事务通知 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <!--   给那些方法配置事务     -->
    <!--   配置事务的传播性: new   propagation="REQUIRED"  默认的     -->
            <tx:attributes>
                <tx:method name="add" propagation="REQUIRED"/>
                <tx:method name="delete" propagation="REQUIRED"/>
                <tx:method name="update" propagation="REQUIRED"/>
                <tx:method name="query" read-only="true"/>
                <tx:method name="*" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
    
    <!--  配置事务的切入  -->
        <aop:config>
            <aop:pointcut id="txPointCut" expression="execution(* com.lmq.mapper.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
        </aop:config>
    

    在这里插入图片描述

  • 编程式事务: 需要在代码中,进行事务的管理

思考:

为什么需要事务?

  • 如果不配做事务,可能纯在数据提交不一致的情况
  • 如果我们不再Spring中去配置声明式事务,我们就需要再代码中手动配置事务!
  • 事务在项目的开发中十分重要,设计到数据的一致性和完整性问题,不容马虎
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  2Vtxr3XfwhHq   2024年05月17日   53   0   0 Java
  Tnh5bgG19sRf   2024年05月20日   109   0   0 Java
  8s1LUHPryisj   2024年05月17日   46   0   0 Java
  aRSRdgycpgWt   2024年05月17日   47   0   0 Java
BbWWsUV3fzWQ
作者其他文章 更多