注意:实体,必须要有空参,全参构造方法,和setter方法
第一步:实体
public class Car {
private String name;
private Double price;
public Car() {
}
public Car(String name, Double price) {
this.name = name;
this.price = price;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(Double price) {
this.price = price;
}
第二步:配置
<!--p标签注入-->
<bean id="car2" class="it.heima.domain.Car"
p:name="宝马" p:price="1200000"/>
第三步:测试
@Test
public void test(){
ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
Car car = applicationContext.getBean("car2", Car.class);
System.out.println(car);
}