How to inject the param?
There are two way...
[color=red][b]The first way:[/b][/color]
package Apple;
public class Apples {
AppleDao apple;
public AppleDao getApple() {
return apple;
}
public void setApple(AppleDao apple) {
this.apple = apple;
}
public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}
}
[color=red]Show on ApplicationContext.xml[/color]
<beans>
<bean name="apple" class="Apple.AppleDaoImpl"></bean>
<bean name="apple2" class="Apple.AppleDaoImple"></bean>
<bean name="apples" class="Apple.Apples">
<property name="apple" ref="apple2"></property>
</bean>
</beans>
[color=red][b]The other one:[/b][/color]
package Apple;
public class Apples {
AppleDao apple;
[color=red]public void Apples(AppleDao apple) {
this.apple = apple;
}[/color]
public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}
}
[color=red]Show on ApplicationContext.xml[/color]
<bean name="apples" class="Apple.Apples">
[color=red]<constructor-arg ref="apple2"></constructor-arg>[/color]</bean>
There are two way...
[color=red][b]The first way:[/b][/color]
package Apple;
public class Apples {
AppleDao apple;
public AppleDao getApple() {
return apple;
}
public void setApple(AppleDao apple) {
this.apple = apple;
}
public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}
}
[color=red]Show on ApplicationContext.xml[/color]
<beans>
<bean name="apple" class="Apple.AppleDaoImpl"></bean>
<bean name="apple2" class="Apple.AppleDaoImple"></bean>
<bean name="apples" class="Apple.Apples">
<property name="apple" ref="apple2"></property>
</bean>
</beans>
[color=red][b]The other one:[/b][/color]
package Apple;
public class Apples {
AppleDao apple;
[color=red]public void Apples(AppleDao apple) {
this.apple = apple;
}[/color]
public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}
}
[color=red]Show on ApplicationContext.xml[/color]
<bean name="apples" class="Apple.Apples">
[color=red]<constructor-arg ref="apple2"></constructor-arg>[/color]</bean>