标签:参数 cat set public over oid div generated imp
---恢复内容开始---
一、通过bean的property属性,必须要有set方法
二、通过构造器设置参数
一)PersonServiceImpl中写构造器
public class PersonServiceImpl implements PersonService {
PersonDao personDao;
private String name;
@Override
public void save() {
// TODO Auto-generated method stub
System.out.println("PersonServiceImpl··"+name);
personDao.add();
}
public PersonServiceImpl(PersonDao personDao, String name) {
super();
this.personDao = personDao;
this.name = name;
}
public PersonServiceImpl() {
super();
}
}
二)applicationContext.xml中配置构造器
<bean id="personService" class="com.lovo.u34.service.impl.PersonServiceImpl">
<constructor-arg index="0" type="com.lovo.u34.dao.PersonDao" ref="personDao"></constructor-arg>
<constructor-arg index="1" type="String" value="张三"></constructor-arg>
</bean>
<bean id="personDao" class="com.lovo.u34.dao.impl.PersonDaoImpl">
</bean>
---恢复内容结束---
标签:参数 cat set public over oid div generated imp
原文地址:http://www.cnblogs.com/syj1993/p/7130186.html