Arrays (Primitive arrays/ Secondary Arrays)
· Data type Arrays : <list> tag to pass the primitive values to Array like(int String)
<list>
<value>Hello</value>
<value>Hello</value>
<value>Hello</value>
<list>
|
· Object Arrays : <ref bean=""> tag to pass the secondary values to Array like(Objects)
<list>
<ref bean ="ob1">
<ref bean ="ob2">
<list>
|
Example
package bean;
public class Car {
private Engine[] engine;
private String[] carname;
public Engine[] getEngine() {
return engine;
}
public void setEngine(Engine[] engine) {
this.engine = engine;
}
public String[] getCarname() {
return carname;
}
public void setCarname(String[] carname) {
this.carname = carname;
}
public void getData(){
for(String car : carname){
System.out.println(car);
}
for(Engine eng : engine){
System.out.println(eng.getModel());
}
}
}
----------------------------------------
package bean;
public class Engine {
private int model;
public void setModel(int model) {
this.model = model;
}
public int getModel() {
return model;
}
}
-------------------------------------------
package driver;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import bean.Car;
public class SpringHello {
public static void main(String[] args) {
ApplicationContext c = new ClassPathXmlApplicationContext("res/s.xml");
Car b = (Car)c.getBean("c");
b.getData();
}
}
--------------------------------------------------------------
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
<beans>
<bean id="e1" class="bean.Engine">
<property name="model" value="2013"></property>
</bean>
<bean id="e2" class="bean.Engine">
<property name="model" value="2014"></property>
</bean>
<bean id="e3" class="bean.Engine">
<property name="model" value="2015"></property>
</bean>
<bean id="c" class="bean.Car">
<property name="carname">
<list>
<value>AUDI</value>
<value>benz</value>
<value>HONDA</value>
</list>
</property>
<property name="engine">
<list>
<ref bean="e1"/>
<ref bean="e2"/>
<ref bean="e3"/>
</list>
</property>
</bean>
</beans>