spring-dataops-beanWrapper

spring-dataops-propertyEditor
master
xuchengsheng 2023-12-05 20:40:52 +08:00
parent 88400b61bf
commit fb5c3db157
10 changed files with 120 additions and 2 deletions

View File

@ -313,11 +313,9 @@
📢 想要一起加入我们的精彩微信群吗?跟着以下简单步骤:
1**扫描我的二维码**:使用微信的扫一扫功能,扫描下方的二维码,将我添加为你的好友。
<div>
<img alt="logo" src="image/wechat-group.jpg" style="width: 344px;height: 483px">
</div>
2**等待好友请求被接受**:一旦你的好友请求被接受,你将收到一份群组邀请。
3**点击邀请链接**:打开邀请链接,立即加入我们的精彩群组!

View File

@ -13,6 +13,8 @@
<packaging>pom</packaging>
<modules>
<module>spring-dataops-validator</module>
<module>spring-dataops-beanWrapper</module>
<module>spring-dataops-propertyEditor</module>
</modules>
</project>

View File

@ -0,0 +1,14 @@
<?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">
<parent>
<artifactId>spring-dataops</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-dataops-beanWrapper</artifactId>
</project>

View File

@ -0,0 +1,35 @@
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

@ -0,0 +1,23 @@
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

@ -0,0 +1,24 @@
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

@ -0,0 +1,14 @@
<?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">
<parent>
<artifactId>spring-dataops</artifactId>
<groupId>com.xcs.spring</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-dataops-propertyEditor</artifactId>
</project>

View File

@ -0,0 +1,8 @@
package com.xcs.spring;
public class PropertyEditorDemo {
public static void main(String[] args) {
}
}