在java里面构造带参数的构造器
package service.impl;
import service.PersonService;
import dao.PersonDAO;
public class PersonServiceImpl1 implements PersonService{
private PersonDAO personDao;
private String name;
private Integer id;
public PersonServiceImpl1(PersonDAO personDao, String name, Integer id) {
super();
this.personDao = personDao;
this.name = name;
this.id = id;
}
/*public PersonServiceImpl1() {
super();
}*/
@Override
public void save() {
System.out.println(name+"-------------"+id);
personDao.add();
}
}
<!-- 使用构造器注入 -->
<bean id="ss1" class="service.impl.PersonServiceImpl1">
<constructor-arg index="0" type="dao.PersonDAO" ref="personDao"/>
<constructor-arg index="1" value="易家享"/>
<constructor-arg index="2" value="99"/>
</bean>
<bean id="personDao" class="dao.impl.PersonDaoImpl"></bean>
type是构造器里面元素的类型 <constructor-arg index="" type="">