本文供以下文章參考使用:
在石景山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需網(wǎng)站策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),全網(wǎng)整合營銷推廣,外貿(mào)網(wǎng)站制作,石景山網(wǎng)站建設(shè)費(fèi)用合理。Spring筆記https://blog.csdn.net/qq_34378496/article/details/128095043java對象:
package com.evenif.bean;
public class Index {
private int id;
private String name;
//無參構(gòu)造方法
public Index() {
System.out.println("create Index class");
}
//兩個參數(shù)的構(gòu)造方法
public Index(int id, String name) {
this.id = id;
this.name = name;
System.out.println("create Index class with params");
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Index{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
beans.xml配置文件:
測試主函數(shù)
package com.evenif;
import com.evenif.bean.Index;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) {
//注意這個xml文件位置要放對
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Index index01 = (Index) context.getBean("index01");
System.out.println(index01);
Index index02 = (Index) context.getBean("index02");
System.out.println(index02);
Index index04 = (Index) context.getBean("index04");
System.out.println(index04);
Index index06 = (Index) context.getBean("index06");
System.out.println(index06);
}
}
//執(zhí)行結(jié)果:注意,即使不獲取index01或index02依然會調(diào)用兩個構(gòu)造方法,
//當(dāng)執(zhí)行 ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); 時對象就創(chuàng)建了。
// create Index class
// create Index class with params
// create Index class with params
// create Index class with params
// Index{id=0, name='ip01'}
// Index{id=1, name='ca02'}
// Index{id=4, name='ca04'}
// Index{id=6, name='ca06'}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
網(wǎng)站標(biāo)題:Spring實例參考03-通過構(gòu)造方法創(chuàng)建對象-創(chuàng)新互聯(lián)
本文地址:http://www.chinadenli.net/article40/dhcpeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、靜態(tài)網(wǎng)站、小程序開發(fā)、用戶體驗、云服務(wù)器、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容