Qing 1 жил өмнө
parent
commit
46687bba3a

+ 38 - 0
spring-demo/.gitignore

@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 8 - 0
spring-demo/.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 7 - 0
spring-demo/.idea/encodings.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+  </component>
+</project>

+ 5 - 0
spring-demo/.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,5 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+  </profile>
+</component>

+ 6 - 0
spring-demo/.idea/kotlinc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="KotlinJpsPluginSettings">
+    <option name="version" value="2.0.0-Beta2" />
+  </component>
+</project>

+ 15 - 0
spring-demo/.idea/misc.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+    <option name="workspaceImportForciblyTurnedOn" value="true" />
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 124 - 0
spring-demo/.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 50 - 0
spring-demo/pom.xml

@@ -0,0 +1,50 @@
+<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>
+
+  <groupId>com.sf</groupId>
+  <artifactId>spring-demo</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>spring-demo</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <kotlin.version>2.0.0-Beta2</kotlin.version>
+  </properties>
+
+  <dependencies>
+<!--    <dependency>-->
+<!--      <groupId>junit</groupId>-->
+<!--      <artifactId>junit</artifactId>-->
+<!--      <version>3.8.1</version>-->
+<!--      <scope>test</scope>-->
+<!--    </dependency>-->
+
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <version>5.10.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+      <version>6.1.2</version>
+    </dependency>
+
+    <!-- maven search -->
+<!--    <dependency>-->
+<!--      <groupId>org.springframework</groupId>-->
+<!--      <artifactId>spring-context</artifactId>-->
+<!--      <version>6.1.1</version>-->
+<!--    </dependency>-->
+
+
+  </dependencies>
+
+
+</project>

+ 137 - 0
spring-demo/src/main/java/com/sf/TestReflect.java

@@ -0,0 +1,137 @@
+package com.sf;
+
+// 反射
+// 面向对象
+//    类和对象
+//    别人帮我们创建对象  通过类创建
+
+// public class User{
+//    String name;
+//    void setName(){}
+// }
+
+// 代码也是对象
+//   User是类的对象   name是属性的对象   String是属性的数据类型对象  setName是方法的对象
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+public class TestReflect {
+
+    public static void main(String[] args) throws Exception {
+        // 通过Class类 找到一个路径所对应的类文件
+        //   通过类文件 newInstance()方法来创建对象
+//        Class userClass = Class.forName("com.sf.User");
+//        User user = (User)userClass.newInstance();
+//        System.out.println(user);
+//
+//        Class otherClass = user.getClass();
+//        Class threeClass = User.class;
+//        System.out.println(userClass == otherClass);
+//        System.out.println(userClass == threeClass);
+
+//        testField();
+//        testMethod();
+
+
+        testInvoke();
+    }
+
+    public static void test() throws Exception {
+        Class userClass = Class.forName("com.sf.User");
+        //  userClass.newInstance();  已废弃
+        //  jdk9以后 更支持通过构造器来创建对象
+        User student = (User) userClass.getDeclaredConstructor().newInstance();
+        // 可以访问私有的属性吗?
+        // 通过指定名字获取属性
+        Field nameField = userClass.getDeclaredField("name");
+        // 给name属性赋值
+        // 对属性的使用  要明确是哪一个对象的属性
+        //  student.name = "zhangdan";
+        //  student.desc = "something";
+        //  Field descField = userClass.getDeclaredField("desc");
+        //  descField.set(student,"something");
+        nameField.setAccessible(true);
+        nameField.set(student, "zhangsan");
+        // 获取name属性的值
+        //  sout(student.name)
+        System.out.println(nameField.get(student));
+    }
+
+    public static void testInvoke() throws Exception {
+        //使用反射机制调用方法
+        Class objClass = Class.forName("com.sf.User");
+        // 创建对象
+        Object obj = objClass.newInstance();
+        // void setName(String name){}
+        // 获取Method
+        Method setMethod = objClass.getDeclaredMethod("setName", String.class);
+        // 调用方法
+        Object resValues = setMethod.invoke(obj, "admin");//注:方法返回值是void 结果是null
+        // String toString(){}
+        Method toStringMethod = objClass.getDeclaredMethod("toString"); // 没有形参就不传
+        Object resValues1 = toStringMethod.invoke(obj);
+        System.out.println(resValues);
+        System.out.println(resValues1);
+    }
+
+    public static void testField() throws ClassNotFoundException {
+        StringBuilder s = new StringBuilder();
+
+
+        /**
+         * public class User {
+         *     private String name;
+         *     private String desc;
+         *  }
+         */
+        Class userClass = Class.forName("java.lang.String");
+//        Class userClass = Class.forName("com.sf.User");
+        // 获取类的修饰符 + class + 类名
+        //   修饰符本身是数字  转化成字符串  然后拼接其他
+        s.append(Modifier.toString(userClass.getModifiers()) + " class "
+                + userClass.getSimpleName() + " { \n");// Class类的getName方法
+        // 获取所有的属性  返回由属性构成的数组
+        // 区别getFields()
+        Field[] fields = userClass.getDeclaredFields();
+        for (Field f : fields) {
+            //  属性的修饰符 属性的类型 属性的名字
+            //  private String name;
+            s.append("\t");
+            // 获取属性的修饰符列表,返回的修饰符是一个数字,每个数字是修饰符的代号
+            // 用Modifier类的toString转换成字符串
+            // 「private」 「String」 name;
+            s.append(Modifier.toString(f.getModifiers()));
+            if (f.getModifiers() != 0) s.append(" ");
+            // private 「String」 name;
+            s.append(f.getType().getSimpleName());// 获取属性的类型
+            s.append(" ");
+            s.append(f.getName());// 获取属性的名字
+            s.append(";\n");
+        }
+        s.append("}");
+        System.out.println(s);
+    }
+
+
+    /**
+     * 李小龙
+     *
+     * @throws ClassNotFoundException
+     */
+    public static void testMethod() throws ClassNotFoundException {
+        StringBuilder s = new StringBuilder();
+        Class userClass = Class.forName("com.sf.User");
+//        userClass.getDeclaredMethods();
+        Method[] methods = userClass.getMethods();
+        for (Method method : methods) {
+            s.append(Modifier.toString(method.getModifiers()) + " " +
+                    method.getReturnType().getSimpleName() + " " +
+                    method.getName() + " { }\n");
+            s.append("");
+        }
+        System.out.println(s);
+    }
+
+}

+ 70 - 0
spring-demo/src/main/java/com/sf/User.java

@@ -0,0 +1,70 @@
+package com.sf;
+
+// 面向对象
+// 类里面有什么 (成员)
+//    属性(变量 基础数据类型 or 引用数据类型)
+//    行为(方法/函数  方法名 + 形参「构成重载」  返回类型 return)
+//          一定是被类或者对象调用   static修饰的被类调用  其他都是被对象调用的
+//          先有类后有对象    静态的只能调用静态的  非静态的都可以调用
+//          类或者属性或者方法  不想被修改的时候  通过final修饰
+//             类被修改 叫做继承  方法被修改 叫做重写   属性被修改 叫做赋值
+//    构造器(特殊的方法) new调用的    new出来的对象 放在了“堆”中
+//          “栈”和“堆”   一个相对较小  一个相对较大
+//             所谓的垃圾回收  是把放在堆中的对象  不再使用的识别为垃圾  进行回收
+//          无参构造器 和 有参构造器(全参构造器)
+//          A类继承B类的时候   new A() 会默认调用父类的构造器
+//    代码块  只能被static修饰 变成静态代码块  非静态代码块 其实就是所有构造器中重复逻辑的抽离
+//          所以也叫初始化块    父类有静态代码块 非静态代码块 构造器  子类有静态代码块 非静态代码块 构造器
+//    内部类
+
+//    封装 private String name;   get和set方法  JavaBean
+//    属性和方法
+//    多态 instanceof   在继承的情况下     A extends B;   B b = new A();
+//                     在接口实现的情况下   C implements D;   D d = new C();
+//      b instanceof A
+//      d instanceof C
+
+//    Object类
+//      hashCode()  equals()  toString()
+public class User {
+
+    private String name;
+    private String desc;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    {
+//        System.out.println("User");
+    }
+
+    public User() {
+//        System.out.println("User");
+    }
+
+    public User(String name) {
+        System.out.println("User by name");
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+                "name='" + name + '\'' +
+                ", desc='" + desc + '\'' +
+                '}';
+    }
+}

+ 52 - 0
spring-demo/src/main/java/com/sf/self/BeanDefined.java

@@ -0,0 +1,52 @@
+package com.sf.self;
+
+import java.util.List;
+
+public class BeanDefined {
+    // bean的唯一id 一个名字
+    private String beanId;
+    // bean所对应的类路径
+    private String classPath;
+    // bean的子标签 property
+    private List<PropertyDefined> propertyDefinedList;
+    // name:name,value:zhangsan
+    // name:desc,value:something
+
+    public BeanDefined() {
+    }
+
+    public BeanDefined(String beanId, String classPath) {
+        this.beanId = beanId;
+        this.classPath = classPath;
+    }
+
+    public BeanDefined(String beanId, String classPath, List<PropertyDefined> propertyDefinedList) {
+        this.beanId = beanId;
+        this.classPath = classPath;
+        this.propertyDefinedList = propertyDefinedList;
+    }
+
+    public List<PropertyDefined> getPropertyDefinedList() {
+        return propertyDefinedList;
+    }
+
+    public void setPropertyDefinedList(List<PropertyDefined> propertyDefinedList) {
+        this.propertyDefinedList = propertyDefinedList;
+    }
+
+    public String getBeanId() {
+        return beanId;
+    }
+
+    public void setBeanId(String beanId) {
+        this.beanId = beanId;
+    }
+
+    public String getClassPath() {
+        return classPath;
+    }
+
+    public void setClassPath(String classPath) {
+        this.classPath = classPath;
+    }
+}

+ 49 - 0
spring-demo/src/main/java/com/sf/self/BeanFactory.java

@@ -0,0 +1,49 @@
+package com.sf.self;
+
+import java.util.List;
+
+// 生产bean的工厂
+//   先要获取对bean的配置   id class
+//    存储这多个bean的配置  beanDefinedList
+public class BeanFactory {
+    // user  com.sf.User
+    // user1  com.sf.User
+    private List<BeanDefined> beanDefinedList;
+
+    public BeanFactory(List<BeanDefined> beanDefinedList) {
+        this.beanDefinedList = beanDefinedList;
+    }
+
+    public List<BeanDefined> getBeanDefinedList() {
+        return beanDefinedList;
+    }
+
+    public void setBeanDefinedList(List<BeanDefined> beanDefinedList) {
+        this.beanDefinedList = beanDefinedList;
+    }
+
+    // 模拟通过beanId 获取bean
+    //  返回的是对象
+    public Object getBean(String beanId){
+        // user2  com.sf.User
+        // user1  com.sf.User
+        // user  com.sf.User
+        Object obj = null;
+        for (BeanDefined beanDefined : beanDefinedList) {
+            // 判断当前的bean是否是传进来的id
+            if(beanDefined.getBeanId().equals(beanId)){
+                String classPath = beanDefined.getClassPath();
+                List<PropertyDefined> propertyDefinedList = beanDefined.getPropertyDefinedList();
+                try {
+                    Class beanClass =  Class.forName(classPath);
+                    obj = beanClass.getDeclaredConstructor().newInstance();
+                } catch (Exception e) {
+//                    throw new RuntimeException(e);
+                    e.printStackTrace();
+                }
+                return obj;
+            }
+        }
+        return obj;
+    }
+}

+ 23 - 0
spring-demo/src/main/java/com/sf/self/PropertyDefined.java

@@ -0,0 +1,23 @@
+package com.sf.self;
+
+public class PropertyDefined {
+
+    private String name;
+    private String value;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

+ 22 - 0
spring-demo/src/main/java/com/sf/self/TestSelf.java

@@ -0,0 +1,22 @@
+package com.sf.self;
+
+import com.sf.User;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestSelf {
+
+    public static void main(String[] args) {
+        BeanDefined userBean = new BeanDefined("user","com.sf.User");
+        BeanDefined userBean1 = new BeanDefined("user1","com.sf.User");
+
+        List<BeanDefined> list = new ArrayList<>();
+        list.add(userBean);
+        list.add(userBean1);
+
+        BeanFactory beanFactory = new BeanFactory(list);
+        User user = (User) beanFactory.getBean("user");
+        System.out.println(user);
+    }
+}

+ 35 - 0
spring-demo/src/main/java/com/sf/test/StaticInterview.java

@@ -0,0 +1,35 @@
+package com.sf.test;
+
+public class StaticInterview extends Base {
+
+    {
+        System.out.println("interview init 1");
+    }
+
+    static {
+        System.out.println("interview static 2");
+    }
+
+    public StaticInterview() {
+        System.out.println("interview constructor 3");
+    }
+
+    public static void main(String[] args) {
+        new StaticInterview();
+    }
+}
+
+class Base {
+
+    {
+        System.out.println("base init 4");
+    }
+
+    static {
+        System.out.println("base static 5");
+    }
+
+    public Base() {
+        System.out.println("base constructor 6");
+    }
+}

+ 17 - 0
spring-demo/src/main/resources/bean.xml

@@ -0,0 +1,17 @@
+<?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="user" class="com.sf.User">
+        <!-- 在bean标签下 有一个子标签 property 就是属性的意思 -->
+        <!--    property标签  自己的标签属性有 name 和 value  对应变量名和变量的值 -->
+        <!--    本质上是调用属性的set方法  官网上叫做set注入-->
+        <property name="name" value="zhangsan"></property>
+        <property name="desc" value="something"></property>
+    </bean>
+
+
+    <bean id="user1" class="com.sf.User"></bean>
+</beans>

+ 31 - 0
spring-demo/src/test/java/com/sf/TestBean.java

@@ -0,0 +1,31 @@
+package com.sf;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class TestBean {
+
+    @Test
+    public void test(){
+        // 要创建bean 需要使用spring提供的容器 (context 上下文)
+        // 应用容器 是个接口
+        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
+        User user = (User) context.getBean("user");
+        // 调用了无参构造器  如果有代码块 也会调用代码块
+        System.out.println(user);
+
+        User user1 = (User) context.getBean("user1");
+        System.out.println(user1);
+    }
+
+    @Test
+    public void test1(){
+        User user = new User();
+
+        User user1 = new User();
+        user1.setName("zhangsan");
+
+        User user2 = new User("lisi");
+    }
+}

+ 37 - 0
spring-demo/src/test/java/com/sf/TestLSY.java

@@ -0,0 +1,37 @@
+package com.sf;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+public class TestLSY {
+
+    public static void main(String[] args) throws ClassNotFoundException {
+        testMethod();
+    }
+
+    public static void testMethod() throws ClassNotFoundException {
+        StringBuilder s = new StringBuilder();
+        Class userClass = Class.forName("com.sf.User");
+        Method[] declaredMethods = userClass.getDeclaredMethods();
+        for (Method m : declaredMethods) {
+            s.append(Modifier.toString(m.getModifiers())
+                    + " " + m.getReturnType().getSimpleName()
+                    + " " + m.getName() + "(");
+            Class<?>[] parameterTypes = m.getParameterTypes();
+
+//            int parameterCount = m.getParameterCount();
+            for (int i = 0; i < parameterTypes.length; i++) {
+                s.append(parameterTypes[i].getSimpleName());
+                s.append(" ");
+//                s.append(parameterCount);
+            }
+            s.append(") {\n");
+            s.append("\t");
+            s.append("\n");
+            s.append("}");
+            s.append("\n");
+        }
+
+        System.out.println(s);
+    }
+}

+ 32 - 0
spring-demo/src/test/java/com/sf/TestTang.java

@@ -0,0 +1,32 @@
+package com.sf;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+/*
+@Author 唐振亮
+@Create 2024/1/9  13:58
+@Name Reflect
+*/
+public class TestTang {
+    public static void main(String[] args) throws ClassNotFoundException {
+        StringBuilder s = new StringBuilder();
+        Class userClass = Class.forName("com.sf.User");
+        String modifier = Modifier.toString(userClass.getModifiers());
+        System.out.println(modifier);
+        String name = userClass.getName();
+        System.out.println(name);
+        s.append("这个类里面的方法有:{" + "\n");
+        Method[] methods = userClass.getDeclaredMethods();
+        for (Method method : methods) {
+            String methodMod = Modifier.toString(method.getModifiers());
+            Class<?> returnType = method.getReturnType();
+            String name2 = returnType.getSimpleName();
+            String name1 = method.getName();
+            s.append(methodMod + " " + name2 + " " + name1 + "\n");
+        }
+        s.append("}");
+        System.out.println(s);
+    }
+
+}

+ 57 - 0
spring-demo/src/test/java/com/sf/TestZFX.java

@@ -0,0 +1,57 @@
+package com.sf;
+
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+public class TestZFX {
+
+    /**
+     * 张甫鑫
+     * @throws Exception
+     */
+    @Test
+    public void test01() throws Exception {
+        Class<?> userClass = Class.forName("com.sf.User");
+        StringBuilder s = new StringBuilder();
+        /*获取到第一行*/
+        s.append(Modifier.toString(userClass.getModifiers()) + " class " +
+                userClass.getSimpleName() + "{\n");
+        /*获取所有的属性,返回由属性构成的数组*/
+        Field[] fields = userClass.getDeclaredFields();
+        for (Field f : fields) {
+            s.append("\t");
+            s.append(Modifier.toString(f.getModifiers()));
+            if (f.getModifiers() != 0) s.append(" ");
+            /*获取属性的类型*/
+            s.append(f.getType().getSimpleName());
+            s.append(" ");
+            /*获取属性的名字*/
+            s.append(f.getName());
+            s.append(";\n");
+        }
+        s.append("\t");
+        /*获取所有的方法*/
+        Method[] allMethod = userClass.getDeclaredMethods();
+        for (Method method : allMethod) {
+            s.append(Modifier.toString(method.getModifiers()) + " ");
+            s.append(method.getReturnType().getSimpleName() + " ");
+            s.append(method.getName() + " (");
+            Class<?>[] parameterTypes = method.getParameterTypes();
+            int flag = 0;
+            for (Class<?> p : parameterTypes) {
+                if (flag == 0) {
+                    s.append(p.getSimpleName());
+                    flag++;
+                    continue;
+                }
+                s.append("," + p.getSimpleName());
+            }
+            s.append(")\n\t");
+        }
+        s.append("}");
+        System.out.println(s);
+    }
+}