, "" JavaBean.
Bean
JavaBeans ( Spring) Bean , Getter / Setter, :
'Bar foo', getter Bar getFoo() ( isFoo() ), setter setFoo(Bar) ( ), "Foo". , , .
. ( JavaBeans) Bean "foo" Integer, iAmNotFoo String.
public class Dummy {
private String iAmNotFoo;
public Integer getFoo() {
return Integer.valueOf(this.iAmNotFoo);
}
public void setFoo(final Integer foo) {
this.iAmNotFoo = foo.toString();
}
}
:
public static void main(final String[] args) throws Exception {
for (final PropertyDescriptor descriptor :
Introspector
.getBeanInfo(Dummy.class, Object.class)
.getPropertyDescriptors()) {
System.out.println(
"Property: "
+ descriptor.getName()
+ ", type: "
+ descriptor.getPropertyType()
);
}
for (final Field field : Dummy.class.getDeclaredFields()) {
System.out.println(
"Field: "
+ field.getName()
+ ", type: "
+ field.getType());
}
}
:
: foo, type: class java.lang.Integer
: iAmNotFoo, type: class java.lang.String
Spring
, Spring . , Bean,
<bean class="Dummy">
<property name="foo" value="123" />
</bean>
"foo" Bean "foo" , , setFoo()
, :
public class Dummy2 {
private List<String> foos;
public void setFoos(List<String> foos) {
this.foos = foos;
}
public void setFoo(String foo){
this.foos = Collections.singletonList(foo);
}
}
<bean class="Dummy2">
<property name="foo" value="123" />
<property name="foos">
<util:list>
<value>Abc</value>
<value>Xyz</value>
<value>123</value>
<value>789</value>
</util:list>
</property>
</bean>
, Spring, .
, JavaBeans : Field!= , , .