2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

spring通過構(gòu)造器的方式bean注入(方法二)

 魏祖清 2016-09-11
Car類
public class Car {
private String brand;
private String corp;
private double price;
private int maxSpend;
public Car(String brand, String corp, double price) {
super();
this.brand = brand;
this.corp = corp;
this.price = price;
}
get和set方法......
構(gòu)造器
public Car(String brand, String corp, int maxSpend) {
super();
this.brand = brand;
this.corp = corp;
this.maxSpend = maxSpend;
}

@Override
public String toString() {
return "Car [brand=" + brand + ", corp=" + corp + ", price=" + price
+ ", maxSpend=" + maxSpend + "]";
}
}
xml配置
<!-- 通過構(gòu)造方法來配置bean的屬性 使用構(gòu)造器可以指定參數(shù)的位置和參數(shù)的類型,一區(qū)分重載的構(gòu)造器 -->
<bean id="car" class="com.wzq.spring.bears.collection.Car">
<constructor-arg value="Audi" index="0"></constructor-arg>
<constructor-arg value="Shanghai" index="1"></constructor-arg>
<constructor-arg value="30000" type="double"></constructor-arg>
</bean>
<bean id="car2" class="com.wzq.spring.bears.collection.Car">
<constructor-arg value="Baoma" type="String"></constructor-arg>
<constructor-arg type="String">
<!-- value值可以直接配置 -->
<!-- 如果包含特殊字符,使用<![CDATA[]]> -->
<value><![CDATA[<^Shanghai^>]]></value>
</constructor-arg>
<constructor-arg value="300" type="int"></constructor-arg>
</bean>
main方法
public class Mian {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
Car car = (Car) ctx.getBean("car");
System.out.println(car);
}
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多