优化目录

master
linlei 2024-03-15 11:50:24 +08:00
parent e4ab4f7359
commit 321363bc50
11 changed files with 51 additions and 142 deletions

View File

@ -84,8 +84,6 @@
- [ConversionService](spring-dataops/spring-dataops-conversionService/README.md):提供统一的类型转换服务接口,管理转换器。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [ConversionService](spring-dataops/spring-dataops-conversionService/README.md):提供统一的类型转换服务接口,管理转换器。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Printer](spring-dataops/spring-dataops-printer/README.md):用于将对象格式化为文本,专注于格式化输出。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [Printer](spring-dataops/spring-dataops-printer/README.md):用于将对象格式化为文本,专注于格式化输出。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [Parser](spring-dataops/spring-dataops-parser/README.md):用于将文本解析为对象,专注于解析逻辑。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [Parser](spring-dataops/spring-dataops-parser/README.md):用于将文本解析为对象,专注于解析逻辑。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- BeanWrapper用于操作JavaBean的属性实现动态属性设置和获取。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>
- AnnotationFormatterFactory针对带注解字段的格式化器工厂链接注解与格式化逻辑。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>
+ Spring 表达式语言SpEL + Spring 表达式语言SpEL
- [ExpressionParser](spring-spel/spring-spel-expressionParser/README.md): 解析字符串形式的 SpEL 表达式,创建并返回 Expression 实例。<img src="https://img.shields.io/badge/Level-%E5%9B%B0%E9%9A%BE-%23FF3030"></img> - [ExpressionParser](spring-spel/spring-spel-expressionParser/README.md): 解析字符串形式的 SpEL 表达式,创建并返回 Expression 实例。<img src="https://img.shields.io/badge/Level-%E5%9B%B0%E9%9A%BE-%23FF3030"></img>
@ -100,20 +98,6 @@
- [TypeComparator](spring-spel/spring-spel-typeLocator/README.md): 类型比较功能,定义了比较两个对象是否相等的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [TypeComparator](spring-spel/spring-spel-typeLocator/README.md): 类型比较功能,定义了比较两个对象是否相等的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [OperatorOverloader](spring-spel/spring-spel-typeLocator/README.md): 运算符重载功能,对表达式中的运算符进行自定义操作的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [OperatorOverloader](spring-spel/spring-spel-typeLocator/README.md): 运算符重载功能,对表达式中的运算符进行自定义操作的方法。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
+ Bean工厂
- [BeanFactory](spring-factory/spring-factory-beanFactory/README.md)Spring的核心接口提供对Bean的配置、创建、管理的基本功能。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ListableBeanFactory](spring-factory/spring-factory-listableBeanFactory/README.md)支持按类型获取Bean的集合。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [HierarchicalBeanFactory](spring-factory/spring-factory-hierarchicalBeanFactory/README.md)支持父子容器关系实现Bean定义的层次结构。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ConfigurableBeanFactory](spring-factory/spring-factory-configurableBeanFactory/README.md)提供对BeanFactory配置的扩展如属性编辑器、作用域等。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
+ [AutowireCapableBeanFactory](spring-factory/spring-factory-autowireCapableBeanFactory/README.md)Bean创建、初始化、注入、销毁的核心功能接口。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
+ [ConfigurableListableBeanFactory](spring-factory/spring-factory-configurableListableBeanFactory/README.md)支持配置和列表操作的可配置Bean工厂接口。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
+ 容器上下文
- [ClassPathXmlApplicationContext](spring-context/spring-context-classPathXmlApplicationContext/README.md)类路径classpath加载 XML 配置文件的上下文。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [AnnotationConfigApplicationContext](spring-context/spring-context-annotationConfigApplicationContext/README.md):注解配置类中加载配置信息的上下文。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- GenericApplicationContext支持多种配置方式XML、注解、手动注册的上下文。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>
+ Bean定义与注册 + Bean定义与注册
- [BeanDefinition](spring-beans/spring-bean-beanDefinition/README.md)详细描述Bean支持依赖注入、AOP、作用域控制等核心功能。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [BeanDefinition](spring-beans/spring-bean-beanDefinition/README.md)详细描述Bean支持依赖注入、AOP、作用域控制等核心功能。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [BeanDefinitionHolder](spring-beans/spring-bean-beanDefinitionHolder/README.md)管理和操作BeanDefinition的关键类。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img> - [BeanDefinitionHolder](spring-beans/spring-bean-beanDefinitionHolder/README.md)管理和操作BeanDefinition的关键类。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
@ -126,6 +110,19 @@
- [AnnotatedBeanDefinitionReader](spring-beans/spring-bean-annotatedBeanDefinitionReader/README.md)注解配置自动扫描注册Spring组件简化Bean定义配置。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [AnnotatedBeanDefinitionReader](spring-beans/spring-bean-annotatedBeanDefinitionReader/README.md)注解配置自动扫描注册Spring组件简化Bean定义配置。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ClassPathBeanDefinitionScanner](spring-beans/spring-bean-classPathBeanDefinitionScanner/README.md)类路径扫描注册Spring Bean支持自动装配。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img> - [ClassPathBeanDefinitionScanner](spring-beans/spring-bean-classPathBeanDefinitionScanner/README.md)类路径扫描注册Spring Bean支持自动装配。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
+ Bean工厂
- [BeanFactory](spring-factory/spring-factory-beanFactory/README.md)Spring的核心接口提供对Bean的配置、创建、管理的基本功能。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ListableBeanFactory](spring-factory/spring-factory-listableBeanFactory/README.md)支持按类型获取Bean的集合。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [HierarchicalBeanFactory](spring-factory/spring-factory-hierarchicalBeanFactory/README.md)支持父子容器关系实现Bean定义的层次结构。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ConfigurableBeanFactory](spring-factory/spring-factory-configurableBeanFactory/README.md)提供对BeanFactory配置的扩展如属性编辑器、作用域等。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [AutowireCapableBeanFactory](spring-factory/spring-factory-autowireCapableBeanFactory/README.md)Bean创建、初始化、注入、销毁的核心功能接口。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
- [ConfigurableListableBeanFactory](spring-factory/spring-factory-configurableListableBeanFactory/README.md)支持配置和列表操作的可配置Bean工厂接口。<img src="https://img.shields.io/badge/Level-%E4%B8%80%E8%88%AC-%23FF6347"></img>
+ 容器上下文
- [ClassPathXmlApplicationContext](spring-context/spring-context-classPathXmlApplicationContext/README.md)类路径classpath加载 XML 配置文件的上下文。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- [AnnotationConfigApplicationContext](spring-context/spring-context-annotationConfigApplicationContext/README.md):注解配置类中加载配置信息的上下文。<img src="https://img.shields.io/badge/Level-%E7%AE%80%E5%8D%95-0099ff"></img>
- GenericApplicationContext支持多种配置方式XML、注解、手动注册的上下文。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>
+ Bean定义导入与组合 + Bean定义导入与组合
- ImportBeanDefinitionRegistrar运行时动态注册 Bean实现灵活配置扩展配置类功能。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img> - ImportBeanDefinitionRegistrar运行时动态注册 Bean实现灵活配置扩展配置类功能。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>
- ImportSelector运行时动态导入配置类实现条件选择和灵活配置。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img> - ImportSelector运行时动态导入配置类实现条件选择和灵活配置。<img src="https://img.shields.io/badge/%E5%8D%B3%E5%B0%86%E6%9B%B4%E6%96%B0-339933"></img>

View File

@ -15,6 +15,7 @@
<modules> <modules>
<module>spring-context-classPathXmlApplicationContext</module> <module>spring-context-classPathXmlApplicationContext</module>
<module>spring-context-annotationConfigApplicationContext</module> <module>spring-context-annotationConfigApplicationContext</module>
<module>spring-context-genericApplicationContext</module>
</modules> </modules>
</project> </project>

View File

@ -3,12 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>spring-dataops</artifactId>
<groupId>com.xcs.spring</groupId> <groupId>com.xcs.spring</groupId>
<artifactId>spring-context</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-dataops-beanWrapper</artifactId> <artifactId>spring-context-genericApplicationContext</artifactId>
</project> </project>

View File

@ -13,7 +13,6 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>spring-dataops-validator</module> <module>spring-dataops-validator</module>
<module>spring-dataops-beanWrapper</module>
<module>spring-dataops-propertyEditor</module> <module>spring-dataops-propertyEditor</module>
<module>spring-dataops-converter</module> <module>spring-dataops-converter</module>
<module>spring-dataops-genericConverter</module> <module>spring-dataops-genericConverter</module>

View File

@ -1,35 +0,0 @@
package com.xcs.spring;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.beans.*;
public class BeanWrapperDemo {
public static void main(String[] args) {
// ok, let's create the director and tie it to the company:
BeanWrapper employee = new BeanWrapperImpl(new Employee());
employee.setPropertyValue("name", "Jim Stravinsky");
employee.setPropertyValue("salary", "100");
BeanWrapper company = new BeanWrapperImpl(new Company());
company.setPropertyValue("name", "Some Company Inc.");
company.setPropertyValue("managingDirector", employee.getWrappedInstance());
// retrieving the salary of the managingDirector through the company
Float salary = (Float) company.getPropertyValue("managingDirector.salary");
System.out.println("salary = " + salary);
System.out.println("company.getPropertyDescriptors() = " + company.getPropertyDescriptors());
try {
BeanInfo beanInfo = Introspector.getBeanInfo(Employee.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
System.out.println("beanInfo.getBeanDescriptor() = " + propertyDescriptors);
} catch (IntrospectionException e) {
e.printStackTrace();
}
}
}

View File

@ -1,23 +0,0 @@
package com.xcs.spring;
public class Company {
private String name;
private Employee managingDirector;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Employee getManagingDirector() {
return this.managingDirector;
}
public void setManagingDirector(Employee managingDirector) {
this.managingDirector = managingDirector;
}
}

View File

@ -1,24 +0,0 @@
package com.xcs.spring;
public class Employee {
private String name;
private float salary;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
}

View File

@ -162,31 +162,21 @@ public interface PropertyAccessor {
### 七、最佳实践 ### 七、最佳实践
使用 `ReflectivePropertyAccessor` 对象来访问对象的属性。首先,创建了一个 `MyBean` 对象,并设置了其属性值。然后,创建了一个 `StandardEvaluationContext` 对象作为属性访问的上下文。接着,通过 `canRead()` 方法判断是否可以读取对象的属性,如果可以则使用 `read()` 方法读取属性值,并通过 `canWrite()` 方法判断是否可以写入属性,如果可以则使用 `write()` 方法更新属性值。最后,输出了更新后的属性值 创建了一个 SpEL 表达式解析器对象 `ExpressionParser`,然后创建了一个 `StandardEvaluationContext` 对象作为 SpEL 表达式的上下文。在上下文中设置了一个名为 `myBean` 的变量,其值为一个 `MyBean` 对象。接着,通过 `parser.parseExpression("#myBean.name")` 解析了一个 SpEL 表达式,该表达式表示访问 `myBean` 对象的 `name` 属性。最后,通过 `getValue(context, String.class)` 方法获取了属性值,并将其输出
```java ```java
public class PropertyAccessorDemo { public class PropertyAccessorDemo {
public static void main(String[] args) throws AccessException { public static void main(String[] args) {
// 创建 ReflectivePropertyAccessor 对象 // 创建一个SpEL表达式解析器
ReflectivePropertyAccessor propertyAccessor = new ReflectivePropertyAccessor(); ExpressionParser parser = new SpelExpressionParser();
// 创建一个对象,我们将在表达式中访问它的属性
MyBean myBean = new MyBean();
myBean.setName("spring-reading");
// 创建一个 EvaluationContext 对象
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("myBean",new MyBean("spring-reading"));
// 演示 read 方法 // 解析SpEL表达式并使用构造函数实例化对象
if (propertyAccessor.canRead(context, myBean, "name")) { String name = parser.parseExpression("#myBean.name").getValue(context, String.class);
System.out.println("Name: " + propertyAccessor.read(context, myBean, "name"));
}
// 演示 write 方法 System.out.println("name = " + name);
if (propertyAccessor.canWrite(context, myBean, "name")) {
propertyAccessor.write(context, myBean, "name", "spring-reading-xcs");
System.out.println("Updated Name: " + myBean.getName());
}
} }
} }
``` ```
@ -198,6 +188,10 @@ public class MyBean {
private String name; private String name;
public MyBean(String name) {
this.name = name;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -205,14 +199,20 @@ public class MyBean {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@Override
public String toString() {
return "MyBean{" +
"name='" + name + '\'' +
'}';
}
} }
``` ```
运行结果发现在输出结果中“Name” 表示读取到的属性值,而 “Updated Name” 则表示经过写入后的新属性值。 运行结果,通过 SpEL 表达式解析器访问了对象的属性,并得到了属性值 "spring-reading"
```properties ```properties
Name: TypedValue: 'spring-reading' of [java.lang.String] name = spring-reading
Updated Name: spring-reading-xcs
``` ```
### 八、与其他组件的关系 ### 八、与其他组件的关系

View File

@ -2,6 +2,10 @@ package com.xcs.spring;
public class MyBean { public class MyBean {
public MyBean(String name) {
this.name = name;
}
private String name; private String name;
// Getters and setters // Getters and setters

View File

@ -12,26 +12,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PropertyAccessorDemo { public class PropertyAccessorDemo {
public static void main(String[] args) throws AccessException { public static void main(String[] args) {
// 创建 ReflectivePropertyAccessor 对象 // 创建一个SpEL表达式解析器
ReflectivePropertyAccessor propertyAccessor = new ReflectivePropertyAccessor(); ExpressionParser parser = new SpelExpressionParser();
// 创建一个对象,我们将在表达式中访问它的属性
MyBean myBean = new MyBean();
myBean.setName("spring-reading");
// 创建一个 EvaluationContext 对象
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.setVariable("myBean",new MyBean("spring-reading"));
// 演示 read 方法 // 解析SpEL表达式并使用构造函数实例化对象
if (propertyAccessor.canRead(context, myBean, "name")) { String name = parser.parseExpression("#myBean.name").getValue(context, String.class);
System.out.println("Name: " + propertyAccessor.read(context, myBean, "name"));
}
// 演示 write 方法 System.out.println("name = " + name);
if (propertyAccessor.canWrite(context, myBean, "name")) {
propertyAccessor.write(context, myBean, "name", "spring-reading-xcs");
System.out.println("Updated Name: " + myBean.getName());
}
} }
} }