锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲AV电影院在线观看,亚洲乱人伦精品图片,亚洲精品视频观看http://www.tkk7.com/kela/category/5298.html            鍓嶉潰鐨勮礬寰堝潕鍧?浣嗘瘯绔熸槸鏉¤礬.涔熻璧拌繃榪欎竴孌靛氨浼?xì)鍙戠?璧拌繃鍘誨氨鏄ⅵ鎯充腑鐨勫湴鏂?鍥犳鍧氭寔鎴愪負(fù)姝ゅ埢鍞竴鑳藉仛涓斿繀欏誨幓鍋氱殑浜嬫儏. zh-cnTue, 27 Feb 2007 13:59:10 GMTTue, 27 Feb 2007 13:59:10 GMT60kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(10)http://www.tkk7.com/kela/articles/80092.htmlKelaKelaThu, 09 Nov 2006 03:54:00 GMThttp://www.tkk7.com/kela/articles/80092.htmlhttp://www.tkk7.com/kela/comments/80092.htmlhttp://www.tkk7.com/kela/articles/80092.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/80092.htmlhttp://www.tkk7.com/kela/services/trackbacks/80092.html 鎽樿錛氫嬌鐢?span lang="EN-US">JDBCTemplate

聽(tīng)

瀵逛簬涓涓熀鏈殑JDBC瀛樺彇錛?span lang="EN-US">Connection鐨勫彇寰楋紝Statement鐨勫緩绔嬶紝寮傚父澶勭悊錛?span lang="EN-US">Statement鐨勫叧闂紝Connection鐨勫叧闂繖浜涙祦紼嬪ぇ鑷村湪涓嶅悓鐨勬暟鎹簱鎶鏈笂澶ц嚧鏄浉鍚岀殑銆?span lang="EN-US">Spring鎻愪緵鐨?span lang="EN-US">JdbcTemplate綾伙紝琚璁′負(fù)綰跨▼瀹夊叏錛屽綋涓墍鎻愪緵鐨勪竴浜涙搷浣滄柟娉曞皝瑁呬簡(jiǎn)綾諱技涓婇潰鐨勬祦紼嬨?span lang="EN-US">

聽(tīng)

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀵逛簬UserDAO.java鐨?span lang="EN-US">JdbcTemplate鏀硅繘

聽(tīng)

鍙渶瑕佹敼榪涚浉搴旂殑鏂規(guī)硶灝卞彲浠ヤ簡(jiǎn)錛屽叾瀹冪殑紼嬪簭涓庢枃浠朵笉鐢ㄥ彉鍔ㄣ?span lang="EN-US">

聽(tīng)

package com.kela.spring.jdbc;

聽(tīng)

import java.util.Iterator;

import java.util.List;

import java.util.Map;

聽(tīng)

import javax.sql.DataSource;

聽(tīng)

import org.springframework.jdbc.core.JdbcTemplate;

聽(tīng)

import com.kela.spring.util.Util;

聽(tīng)

public class Test implements IUserDAO {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private JdbcTemplate jdbcTemplate;

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void setDataSource(DataSource dataSource) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) jdbcTemplate = new JdbcTemplate(dataSource);

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void insert(User user) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String name = user.getName();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) int age = user.getAge().intValue();

聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String sql = "INSERT INTO user (name, age) VALUES ('" + name + "', " + age + ")";

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 杞爜

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) sql = Util.GBKToISO(sql);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) jdbcTemplate.update(sql);

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public User find(Integer id) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String sql = "SELECT * FROM user WHERE id = " + id.intValue();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) List rs = jdbcTemplate.queryForList(sql);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) Iterator it = rs.iterator();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) if(it.hasNext()) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) Map userMap = (Map)it.next();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) Integer i = new Integer(userMap.get("id").toString());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String name = Util.getStr(userMap.get("name").toString());// 杞爜

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) Integer age聽(tīng) = new Integer(userMap.get("age").toString());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) User user = new User();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) user.setId(i);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) user.setAge(age);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) user.setName(name);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return user;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return null;

聽(tīng)聽(tīng)聽(tīng) }

}

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 鍑犵JdbcTemplate鎵ц涓庢洿鏂幫紝鏌ヨ鐨勬紨紺?span lang="EN-US">

聽(tīng)

A錛?span style="FONT: 7pt 'Times New Roman'">聽(tīng) 浣跨敤JdbcTemplate鐨?span lang="EN-US">execute錛堬級(jí)鏂規(guī)硶鎵цSQL闄堣堪銆?span lang="EN-US">

jdbcTemploat.execute(sql);

B錛?span style="FONT: 7pt 'Times New Roman'">聽(tīng) 濡傛灉鏄?span lang="EN-US">Update鎴?span lang="EN-US">insert錛屼嬌鐢?span lang="EN-US">update錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

聽(tīng)

鈥?鈥?鈥?o:p>

浣跨敤棰勭紪璇?span lang="EN-US">SQL錛?span lang="EN-US">

public void insert(User user) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) final String name = user.getName();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) final int age = user.getAge().intValue();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) jdbcTemplate.update(new PreparedStatementCreator() {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String sql = "INSERT INTO user (name, age) VALUES (?, ?)";

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) PreparedStatement ps = conn.prepareStatement(sql);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ps.setString(1, name);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ps.setInt(2, age);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return ps;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) );

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

鈥?鈥?鈥?o:p>

聽(tīng)

public void insert(User user) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) final String name = user.getName();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) final int age = user.getAge().intValue();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) String sql = "INSERT INTO user (name, age) VALUES (?, ?)";

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) jdbcTemplate.update(sql, new PreparedStatementSetter() {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) public void setValues(PreparedStatement ps) throws SQLException {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ps.setString(1, name);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ps.setInt(2, age);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) });

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

鈥?鈥?鈥?o:p>

聽(tīng)

public void insert(User user) {

聽(tīng)聽(tīng)聽(tīng) String sql = "INSERT INTO user (name, age) VALUES (?, ?)";

聽(tīng)聽(tīng)聽(tīng) jdbcTemplate.update(sql, new Object[] {user.getName(), user.getAge()});

}

聽(tīng)

鈥?鈥?鈥?

聽(tīng)

C錛?span style="FONT: 7pt 'Times New Roman'">聽(tīng) 浣跨敤JdbcTemplate榪涜鏌ヨ鏃訛紝鍙槸浣跨敤queryForXXX錛堬級(jí)絳夋柟娉曘?span lang="EN-US">

聽(tīng)

// 榪斿洖涓涓暣鍨?span lang="EN-US">

jdbcTemplate.queryForInt(鈥渟elect count 錛?span lang="EN-US">*錛?span lang="EN-US"> from user鈥?span lang="EN-US">)錛?span lang="EN-US">

聽(tīng)

// 榪斿洖涓涓煡璇㈠悗鐨勭粨鏋滃璞?span lang="EN-US">

jdbcTemplate.queryForObject(鈥渟elect name from user where id = ?鈥?

new Object[] {id},

java.lang.String.class);

聽(tīng)

// 榪斿洖澶氱瑪璧勬枡鐨勫垪琛?span lang="EN-US">

jdbcTemplate.queryForList 錛堚?span lang="EN-US">select * from user鈥?/span>錛?span lang="EN-US">;

聽(tīng)

List 涓寘鎷殑浜?span lang="EN-US">Map瀵硅薄錛屾瘡涓?span lang="EN-US">Map瀵硅薄浠h〃鏌ヨ緇撴灉鐨勪竴琛岃褰曘?span lang="EN-US">

聽(tīng)



Kela 2006-11-09 11:54 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(9)http://www.tkk7.com/kela/articles/80052.htmlKelaKelaThu, 09 Nov 2006 02:32:00 GMThttp://www.tkk7.com/kela/articles/80052.htmlhttp://www.tkk7.com/kela/comments/80052.htmlhttp://www.tkk7.com/kela/articles/80052.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/80052.htmlhttp://www.tkk7.com/kela/services/trackbacks/80052.html闃呰鍏ㄦ枃

Kela 2006-11-09 10:32 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(8)http://www.tkk7.com/kela/articles/80022.htmlKelaKelaThu, 09 Nov 2006 01:30:00 GMThttp://www.tkk7.com/kela/articles/80022.htmlhttp://www.tkk7.com/kela/comments/80022.htmlhttp://www.tkk7.com/kela/articles/80022.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/80022.htmlhttp://www.tkk7.com/kela/services/trackbacks/80022.html

鎽樿錛?span lang="EN-US">Spring鐨?span lang="EN-US">JDBC鏀寔錛?span lang="EN-US">Spring鎻愪緵浜?span lang="EN-US">DAO妗嗘灦錛屾彁渚涗簡(jiǎn)瀵規(guī)暟鎹簱瀛樺彇鏃跺紓甯哥殑灝佽錛屾彁渚涚殑JdbcTemplate綾誨ぇ澶х畝鍖栦簡(jiǎn)JDBC鍦?span lang="EN-US">API涓婄殑鎿嶄綔絳夈?span lang="EN-US">

聽(tīng)

涓涓紶緇?span lang="EN-US">DAO鐨勪緥瀛愩?span lang="EN-US">

濡傦紝鐜板湪鏈変竴涓暟鎹簱琛?span lang="EN-US">user錛岃琛ㄦ湁id錛?span lang="EN-US">name錛?span lang="EN-US">age涓変釜瀛楁銆傚璇ヨ〃鎶借薄寰楀嚭User瀵硅薄錛屽湪榪涜鏁版嵁搴撴搷浣滄椂錛?span lang="EN-US">find錛?span lang="EN-US">insert錛?span lang="EN-US">update錛?span lang="EN-US">delete錛夊簲鐢ㄧ▼搴忎笉搴斾緷璧栦簬涓涓疄闄呯殑綾誨疄鐜幫紝鑰屾槸鍙互璁╁畠渚濊禆涓涓帴鍙o紝鍦ㄥ簲鐢ㄧ▼搴忎腑閫氳繃瀵規(guī)帴鍙g殑澹版槑鏉ユ搷浣溿?span lang="EN-US">

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) User.java

聽(tīng)

榪欐槸User瀵硅薄

聽(tīng)

package com.kela.spring.jdbc;

聽(tīng)

public class User {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private Integer id;

聽(tīng)聽(tīng)聽(tīng) private String name;

聽(tīng)聽(tīng)聽(tīng) private Integer age;

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public Integer getAge() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return age;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setAge(Integer age) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.age = age;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public Integer getId() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return id;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setId(Integer id) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.id = id;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public String getName() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return name;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setName(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.name = name;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) IUserDAO.java

聽(tīng)

榪欐槸IUserDAO鎺ュ彛錛岃礋璐e0鏄庡User瀵硅薄鐨勬搷浣溿?span lang="EN-US">

聽(tīng)

package com.kela.spring.jdbc;

聽(tīng)

public interface IUserDAO {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void insert(User user);

聽(tīng)聽(tīng)聽(tīng) public User find(Integer id);

public void update(User user);

public void delete(User user);

}

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) UserDAO.java

聽(tīng)

鍏蜂綋鐨勬暟鎹簱瀛樺彇綾伙紝瀹炵幇浜?span lang="EN-US">IUserDAO鎺ュ彛銆?span lang="EN-US">

聽(tīng)

package com.kela.spring.jdbc;

聽(tīng)

public class UserDAO implements IUserDAO {

public void insert(User user) {

聽(tīng)聽(tīng)聽(tīng) Connnection conn = null;

聽(tīng)聽(tīng)聽(tīng) Statement stmt = null;

聽(tīng)聽(tīng)聽(tīng) try {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 鎵ц鏁版嵁搴撴彃鍏ユ搷浣?span lang="EN-US">

聽(tīng)聽(tīng)聽(tīng) } catch (SQLException e) {

聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) //鈥?o:p>

聽(tīng)聽(tīng)聽(tīng) } finally{

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) //鈥?o:p>

}

}

聽(tīng)聽(tīng)聽(tīng) public User find(Integer id) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 鏌ヨ

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return user;

}

public void update(User user) {

聽(tīng)聽(tīng)聽(tīng) //鈥?o:p>

}

public void delete(User user) {

聽(tīng)聽(tīng)聽(tīng) //鈥?o:p>

}

}

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) Test.java

聽(tīng)

鍦ㄥ簲鐢ㄧ▼搴忎腑榪涜鏁版嵁瀛樺彇鏃訛紝鍙互浣跨敤IUserDAO鏉ュ0鏄庢帴鍙o紝榪涜鏁版嵁鎿嶄綔銆?span lang="EN-US">

鈥?鈥?o:p>

User user = new User();

user.setId(new Integer(2));

user.setName(鈥渒ela鈥?;

user.setAge(new Integer(28));

聽(tīng)

IUserDAO userDao = new UserDAO();

userDao.insert(user);

聽(tīng)

鈥?鈥?o:p>

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

鐢變簬渚濊禆浜庢帴鍙o紝鎵浠ュ彲浠ラ殢鏃舵浛鎹?span lang="EN-US">IUserDAO鐨勫疄鐜扮被錛屽湪IUserDAO鎺ュ彛澹版槑鐨勬搷浣滄柟娉曚笂騫舵病鏈変換浣曚簬搴曞眰鏁版嵁搴撳瓨鍙栫殑鎶鏈粏鑺傦紝Spring鐨?span lang="EN-US">DAO妗嗘灦榪欐槸鍩轟簬榪欐牱鐨勫師鐞嗭紝灝嗗簲鐢ㄧ▼搴忎笌搴曞眰瀛樺彇鎶鏈殧紱誨紑鏉ャ?span lang="EN-US">

聽(tīng)



Kela 2006-11-09 09:30 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(7)http://www.tkk7.com/kela/articles/66464.htmlKelaKelaTue, 29 Aug 2006 08:35:00 GMThttp://www.tkk7.com/kela/articles/66464.htmlhttp://www.tkk7.com/kela/comments/66464.htmlhttp://www.tkk7.com/kela/articles/66464.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/66464.htmlhttp://www.tkk7.com/kela/services/trackbacks/66464.html 鎽樿錛?span lang="EN-US">Spring AOP 錛屼粠浠g悊鏈哄埗鐪?span lang="EN-US">AOP錛屽姩鎬佷唬鐞嗙殑鑼冧緥

聽(tīng)

鍦?span lang="EN-US">JDK1.3涔嬪悗鍔犲叆浜?jiǎn)鍙崗鍔╁紑鍙戝姩鎬佷唬鐞嗗姛鑳界殑API錛屼綘涓嶅繀涓虹壒瀹氬璞′笌鏂規(guī)硶緙栧啓鐗瑰畾鐨勪唬鐞嗗璞★紝浣跨敤鍔ㄦ佷唬鐞嗭紝鍙互浣跨敤涓涓鐞嗚咃紙Handler錛夋湇鍔′簬鍚勪釜瀵硅薄銆?span lang="EN-US">

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) LogHandler.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

import java.lang.reflect.InvocationHandler;

import java.lang.reflect.Method;

import java.lang.reflect.Proxy;

聽(tīng)

import org.apache.log4j.Logger;

聽(tīng)

public class LogHandler implements InvocationHandler {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private Logger log = Logger.getLogger(this.getClass().getName());

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private Object delegate;

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public Object bind(Object delegate) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.delegate = delegate;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return Proxy.newProxyInstance(delegate.getClass().getClassLoader(), delegate.getClass().getInterfaces(), this);

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public Object invoke(Object arg0, Method method, Object[] args)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) throws Throwable {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) Object result = null;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) try {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log.info("hello 鏂規(guī)硶寮濮嬫墽琛?span lang="EN-US">... ...");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) result = method.invoke(delegate, args);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log.info("hello 鏂規(guī)硶鎵ц瀹屾瘯");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) } catch (Exception e) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println("[ERROR]" + e.getMessage());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return result;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) IHell.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public interface IHello {

聽(tīng)聽(tīng)聽(tīng) public void hello(String name);

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloSpeaker.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public class HelloSpeaker implements IHello {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void hello(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println(" 浣犲ソ錛?span lang="EN-US">" + name);

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) ProxyDemo.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public class ProxyDemo {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void method_2() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) LogHandler logHandler = new LogHandler();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) IHello helloProxy = (IHello)logHandler.bind(new HelloSpeaker());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) helloProxy.hello("kela");

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public static void main(String[] args) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ProxyDemo proxyDemo = new ProxyDemo();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) proxyDemo.method_2();

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

浣跨敤浠g悊瀵硅薄灝嗚褰曠瓑浜庝笟鍔¢昏緫鏃犲叧鐨勫姩浣滄垨浠誨姟鎻愬彇鍑烘潵錛岃璁′負(fù)涓涓湇鍔″璞★紝濡?span lang="EN-US">LogHandler鍜屼笂涓灝忚妭涓殑HelloProxy錛岃繖鏍風(fēng)殑瀵硅薄縐頒箣涓哄垏闈紙Aspect錛夈?span lang="EN-US">



Kela 2006-08-29 16:35 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(6)http://www.tkk7.com/kela/articles/66449.htmlKelaKelaTue, 29 Aug 2006 07:27:00 GMThttp://www.tkk7.com/kela/articles/66449.htmlhttp://www.tkk7.com/kela/comments/66449.htmlhttp://www.tkk7.com/kela/articles/66449.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/66449.htmlhttp://www.tkk7.com/kela/services/trackbacks/66449.html 鎽樿錛?span lang="EN-US">Spring AOP 錛屼粠浠g悊鏈哄埗鐪?span lang="EN-US">AOP錛岄潤(rùn)鎬佷唬鐞嗙殑鑼冧緥銆?span lang="EN-US">

聽(tīng)

鍦ㄤ竴涓湇鍔$殑嫻佺▼涓彃鍏ヤ笌涓氬姟閫昏緫鏃犲叧鐨勭郴緇熸湇鍔¢昏緫錛堟瘮濡?span lang="EN-US"> Logging銆?span lang="EN-US">Security錛夛紝榪欐牱鐨勯昏緫縐頒負(fù)Cross-cutting concerns錛屽皢Cross-cutting concerns鐙珛鍑烘潵璁捐涓轟竴涓璞★紝榪欐牱鐨勭壒孌婂璞$О涔嬩負(fù)Aspect錛?span lang="EN-US">Aspect-oriented programming鐫閲嶅湪Aspect鐨勮璁″強(qiáng)涓庡簲鐢ㄧ▼搴忕殑緇囧叆錛?span lang="EN-US">Weave錛夈?span lang="EN-US">

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 闈?rùn)鎬佷唬鐞?span lang="EN-US">

聽(tīng)

鍦ㄩ潤(rùn)鎬佷唬鐞嗙殑瀹炵幇涓紝浠g悊瀵硅薄涓庤浠g悊瀵硅薄閮藉繀欏誨疄鐜板悓涓涓帴鍙o紝鍦ㄤ唬鐞嗗璞′腑鍙互瀹炵幇鏃ュ織璁板綍絳夌浉鍏蟲湇鍔★紝騫跺湪闇瑕佺殑鏃跺欏啀鍛煎彨琚唬鐞嗙殑瀵硅薄錛屽姝や唬鐞嗗璞″綋涓氨鍙互浠呬繚鐣欎笟鍔$浉鍏寵亴璐c?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) IHello.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public interface IHello {

聽(tīng)聽(tīng)聽(tīng) public void hello(String name);

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloSpeaker.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public class HelloSpeaker implements IHello {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void hello(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println(" 浣犲ソ錛?span lang="EN-US">" + name);

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloProxy.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

import org.apache.log4j.Logger;

聽(tīng)

public class HelloProxy implements IHello {

聽(tīng)聽(tīng)聽(tīng) private Logger log = Logger.getLogger(this.getClass().getName());

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private IHello helloObject;

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public HelloProxy(IHello helloObject) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.helloObject = helloObject;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void hello(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 鏃ュ織璁板綍

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log.info("hello 鏂規(guī)硶寮濮嬫墽琛?span lang="EN-US">... ...");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 鎵ц涓氬姟閫昏緫

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) helloObject.hello(name);

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) // 鏃ュ織璁板綍

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log.info("hello 鏂規(guī)硶鎵ц瀹屾瘯");

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) ProxyDemo.java

聽(tīng)

package com.kela.spring.aop;

聽(tīng)

public class ProxyDemo {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public static void main(String[] args) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloProxy proxy = new HelloProxy(new HelloSpeaker());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) proxy.hello("KELA");

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 榪愯緇撴灉

聽(tīng)

HelloProxy - hello 鏂規(guī)硶寮濮嬫墽琛?/span> ... ...

聽(tīng) 浣犲ソ錛?/span> KELA

HelloProxy - hello 鏂規(guī)硶鎵ц瀹屾瘯

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

闈?rùn)鎬佷唬鐞嗕腑錛屼唬鐞嗗璞$殑涓涓帴鍙e彧鏈嶅姟浜庝竴縐嶇被鍨嬬殑瀵硅薄錛岃屼笖濡傛灉瑕佷唬鐞嗙殑鏂規(guī)硶寰堝錛屽娍蹇呰涓烘瘡涓柟娉曡繘琛屼唬鐞嗭紝闈?rùn)鎬佷唬鐞嗗湪紼嬪簭瑙勬ā紼嶅ぇ鏃跺氨鏃犳硶鑳滀換銆?span lang="EN-US">



Kela 2006-08-29 15:27 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(5)http://www.tkk7.com/kela/articles/65323.htmlKelaKelaWed, 23 Aug 2006 09:36:00 GMThttp://www.tkk7.com/kela/articles/65323.htmlhttp://www.tkk7.com/kela/comments/65323.htmlhttp://www.tkk7.com/kela/articles/65323.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/65323.htmlhttp://www.tkk7.com/kela/services/trackbacks/65323.html 鎽樿錛?span lang="EN-US">Bean鐨勭敓鍛藉懆鏈熴備竴涓?span lang="EN-US">Bean浠庡緩绔嬪埌閿姣侊紝濡傛灉鏄嬌鐢?span lang="EN-US">BeanFactory鏉ョ敓鎴愶紝綆$悊Bean鐨勮瘽錛屼細(xì)緇忓巻鍑犱釜鎵ц闃舵銆?span lang="EN-US">

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) Bean 鐨勫緩绔?span lang="EN-US">

聽(tīng)

鐢?span lang="EN-US">BeanFactory璇誨彇Bean瀹氫箟鏂囦歡錛屽茍鐢熸垚鍚勪釜Bean瀹炰緥銆?span lang="EN-US">

鍦?span lang="EN-US">Spring涓紝榛樿鍙栧緱鐨勫疄渚嬩負(fù)Singleton妯″紡錛屽嵆姣忎竴嬈?span lang="EN-US">context.getBean(鈥渂eanName鈥?鍙栧緱鐨勫璞¢兘鏄悓涓涓紝鑰屼笉鏄瘡嬈¢兘浜х敓涓涓柊鐨勫璞°傚ぇ閮ㄥ垎鎯呭喌涓?span lang="EN-US">Singleton鏄兘澶熸弧瓚寵姹傜殑錛屽鏋滆冭檻鍒扮嚎紼嬪畨鍏ㄧ瓑鐨勯棶棰橈紝闇浣跨敤Prototype妯″紡錛屽嵆姣忔鍙栧緱鐨勫璞¢兘鏄竴涓嫭绔嬬殑瀵硅薄錛屽彧闇瑕佸皢singleton=鈥漟alse鈥?/span>鍗沖彲銆?span lang="EN-US">

聽(tīng)

濡傦細(xì)

聽(tīng)

<bean id= "someBean" class= "com.kela.spring.ioc.SomeBean" singleton= "false" >

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 灞炴ф敞鍏?span lang="EN-US">

聽(tīng)

鎵ц鐩稿叧鐨?span lang="EN-US">Bean灞炴т緷璧栨敞鍏?b style="mso-bidi-font-weight: normal">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) BeanNameAware 鐨?span lang="EN-US">setBeanName錛堬級(jí)

聽(tīng)

濡傛灉Bean綾繪湁瀹炵幇org.springframework.beans.factory.BeanNameAware鎺ュ彛錛屽垯鎵ц瀹冪殑setBaenName錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

瀹炵幇BeanNameAware鎺ュ彛鐨?span lang="EN-US">Bean綾伙紝鍦ㄤ緷璧栧叧緋昏瀹氬畬鎴愬悗錛屽垵濮嬪寲鏂規(guī)硶涔嬪墠錛屽皢Bean鐨勫畾涔夋枃浠朵腑鐨勫悕縐拌瀹氱粰Bean銆?span lang="EN-US">

聽(tīng)

娉細(xì)Spring涓彁渚涗簡(jiǎn)涓浜?span lang="EN-US">Aware鐩稿叧鎺ュ彛錛屽疄鐜拌繖浜?span lang="EN-US">Aware鎺ュ彛鐨?span lang="EN-US">Bean綾誨湪琚垵濮嬪寲涔嬪悗錛屽彲浠ュ彇寰椾竴浜?span lang="EN-US">Spring鎵鎻愪緵鐨勮祫婧愭垨浣跨敤鏌愪簺鍔熻兘銆?span lang="EN-US">

涓鏃﹀疄鐜頒簡(jiǎn)鎻愪緵鐨勭浉鍏蟲帴鍙o紝鍒欏簲鐢ㄧ▼搴忓氨浼?xì)鋴社敤鍒?span lang="EN-US">Spring鐨勭浉鍏?span lang="EN-US">API錛岃屼笌Spring浜х敓鑰﹀悎鍏崇郴銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) BeanFactoryAware 鐨?span lang="EN-US">setBeanFactory錛堬級(jí)

聽(tīng)

濡傛灉bean綾繪湁瀹炵幇org.springframework.beans.factory.BeanFactoryAware鎺ュ彛錛屽垯鎵ц瀹冪殑setBeanFactory銆?span lang="EN-US">

瀹炵幇BeanFactoryAware鎺ュ彛鐨?span lang="EN-US">Bean綾伙紝鍦ㄤ緷璧栧叧緋昏瀹氬畬鎴愬悗錛屽垵濮嬪寲鏂規(guī)硶涔嬪墠錛?span lang="EN-US">Spring瀹瑰櫒灝嗕細(xì)娉ㄥ叆BeanFactory鐨勫疄渚嬨?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) BeanPostProcessor 鐨?span lang="EN-US">postProcessBeforeInitialization錛堬級(jí)

聽(tīng)

濡傛灉浠諱綍鐨?span lang="EN-US">org.springfaramwork.beans.factory.config.BeanPostProcessor瀹炰緥涓?span lang="EN-US">Bean瀹炰緥鍏寵仈錛屽垯鎵цBeanPostProcessors瀹炰緥鐨?span lang="EN-US">postProcessBeforeInitialization錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) InitializingBean 鐨?span lang="EN-US">afterPropertiesSet錛堬級(jí)

聽(tīng)

濡傛灉Bean綾諱互瀹炵幇org.springfaramwork.beans.factory.InitializingBean鎺ュ彛錛屽垯鎵ц瀹冪殑afterPropertiesSet錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) Bean 瀹氫箟鏂囦歡涓畾涔?span lang="EN-US">init-method

聽(tīng)

鍙互鍦?span lang="EN-US">Bean瀹氫箟鏂囦歡浣跨敤鈥?span lang="EN-US">init-method鈥濆睘鎬ц瀹氭柟娉曞悕縐幫紝渚嬪錛?span lang="EN-US">

聽(tīng)

<bean id= "someBean" class= "com.kela.spring.ioc.SomeBean" init-method= "initBean" >

聽(tīng)

濡傛灉鏈変互涓婅瀹氱殑璇濓紝鍒欒繘琛岃嚦榪欎釜闃舵鏃訛紝灝變細(xì)鎵цinitBean錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) BeanPostProcessor 鐨?span lang="EN-US">postProcessAfterInitialization錛堬級(jí)

聽(tīng)

濡傛灉浠諱綍鐨?span lang="EN-US">org.springfaramwork.beans.factory.config.BeanPostProcessor瀹炰緥涓?span lang="EN-US">Bean瀹炰緥鍏寵仈錛屽垯鎵цBeanPostProcessors瀹炰緥鐨?span lang="EN-US">postProcessAfterInitialization錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) DisposableBean 鐨?span lang="EN-US">destroy錛堬級(jí)

聽(tīng)

鍦ㄥ鍣ㄥ叧闂椂錛屽鏋?span lang="EN-US">Bean綾繪湁瀹炵幇org.springframework.beans.factory.DisposableBean鎺ュ彛錛屽垯鎵ц瀹冪殑destroy錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) Bean 瀹氫箟鏂囦歡涓畾涔?span lang="EN-US">destroy-method

聽(tīng)

鍦ㄥ鍣ㄥ叧闂椂錛屽彲浠ュ湪Bean瀹氫箟鏂囦歡涓嬌鐢ㄢ?span lang="EN-US">destroy-method鈥濆睘鎬ц瀹氭柟娉曞悕縐幫紝渚嬪錛?span lang="EN-US">

鈥?o:p>

<bean id= "someBean" class= "com.kela.spring.ioc.SomeBean" destroy-method= "destroyBean" >

聽(tīng)

濡傛灉鏈変互涓婅瀹氱殑璇濓紝鍒欒繘琛岃嚦榪欎釜闃舵鏃訛紝灝變細(xì)鎵цdestroyBean錛堬級(jí)鏂規(guī)硶銆?span lang="EN-US">

聽(tīng)

娉ㄦ剰錛氬鏋滄槸浣跨敤ApplicationContext鏉ョ敓鎴愬茍綆$悊Bean鐨勮瘽鍒欑◢鏈変笉鍚岋紝浣跨敤ApplicationContext鏉ョ敓鎴愬強(qiáng)綆$悊Bean瀹炰緥鐨勮瘽錛屽湪鎵цBeanFactoryAware鐨?span lang="EN-US">setBeanFactory錛堬級(jí)闃舵涔嬪悗錛岃嫢Bean綾諱笂鏈夊疄鐜?span lang="EN-US">org.springframework.context.ApplicationContextAware鎺ュ彛錛屽垯鎵ц鍏?span lang="EN-US">setApplicationContext錛堬級(jí)鏂規(guī)硶錛屾帴鐫鎵嶇戶緇繘琛?span lang="EN-US">BeanPostProcessor鐨?span lang="EN-US">postProcessBeforeInitialization錛堬級(jí)鍙?qiáng)涔嬪悗鐨剫箒绋嬨?span lang="EN-US">



Kela 2006-08-23 17:36 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(4)http://www.tkk7.com/kela/articles/65042.htmlKelaKelaTue, 22 Aug 2006 04:28:00 GMThttp://www.tkk7.com/kela/articles/65042.htmlhttp://www.tkk7.com/kela/comments/65042.htmlhttp://www.tkk7.com/kela/articles/65042.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/65042.htmlhttp://www.tkk7.com/kela/services/trackbacks/65042.html闃呰鍏ㄦ枃

Kela 2006-08-22 12:28 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(3)http://www.tkk7.com/kela/articles/64992.htmlKelaKelaTue, 22 Aug 2006 02:41:00 GMThttp://www.tkk7.com/kela/articles/64992.htmlhttp://www.tkk7.com/kela/comments/64992.htmlhttp://www.tkk7.com/kela/articles/64992.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/64992.htmlhttp://www.tkk7.com/kela/services/trackbacks/64992.html 鎽樿錛氬睘鎬у弬鑰冭嚦瀵硅薄銆備竴涓璞$殑灞炴у弬鑰冨彟涓涓璞$殑瀹炰緥錛屽錛屽鐢燂紙StudentBean錛夊璞℃湁涓や釜灞炴т竴涓槸name涓涓槸addressBean錛?span lang="EN-US">name鏄竴涓?span lang="EN-US">String鍨嬶紝鑰?span lang="EN-US">addressBean鏄?span lang="EN-US">AddressBean瀵硅薄錛堝湴鍧瀵硅薄錛夌殑涓涓疄渚嬨?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) StrudentBean.java

聽(tīng)

package com.kela.spring.ioc;

聽(tīng)

public class StudentBean {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private String name;

聽(tīng)聽(tīng)聽(tīng) private AddressBean addressBean;

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public AddressBean getAddressBean() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return addressBean;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setAddressBean(AddressBean addressBean) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.addressBean = addressBean;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public String getName() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return name;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setName(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.name = name;

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) AddressBean.java

聽(tīng)

package com.kela.spring.ioc;

聽(tīng)

public class AddressBean {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private String addressName;

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public String getAddressName() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return addressName;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void setAddressName(String addressName) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.addressName = addressName;

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) beans-config_2.xml

聽(tīng)

<?xml version= "1.0" encoding= "GB2312" ?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >

聽(tīng)

<beans>

聽(tīng)聽(tīng)聽(tīng) <bean id= "addressBean" class= "com.kela.spring.ioc.AddressBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <property name= "addressName" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> 鍥㈢粨澶ц鍚戦槼璺?/span> 123 鍙?/span> </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng) </bean>

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) <bean id= "studentBean" class= "com.kela.spring.ioc.StudentBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <property name= "name" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> KangFeng </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <property name= "addressBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <!-- 娉ㄦ剰榪欓噷宸蹭笉鏄?/span> value 浜?jiǎn)锛屾敼湄?fù) ref -->

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <ref bean= "addressBean" ></ref>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng) </bean>

</beans>

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) TestClass.java

聽(tīng)

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

聽(tīng)

public class TestClass {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void method_2() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) try {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ApplicationContext context = new FileSystemXmlApplicationContext("bin\\com\\kela\\spring\\ioc\\beans-config_2.xml");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) StudentBean studentBean = (StudentBean)context.getBean("studentBean");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println(" 濮撳悕錛?span lang="EN-US">" + studentBean.getName() + ";鍦板潃錛?span lang="EN-US">" + studentBean.getAddressBean().getAddressName());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) } catch (Exception e) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println("[ERROR]" + e.getMessage());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public static void main(String[] args) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) TestClass testClass = new TestClass();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) testClass.method_2();

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

鈥?span lang="EN-US">Don鈥檛 Call Me錛?span lang="EN-US">I鈥?span lang="EN-US">ll Call You鈥濄?span lang="EN-US">

聽(tīng)



Kela 2006-08-22 10:41 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(2)http://www.tkk7.com/kela/articles/64961.htmlKelaKelaTue, 22 Aug 2006 01:36:00 GMThttp://www.tkk7.com/kela/articles/64961.htmlhttp://www.tkk7.com/kela/comments/64961.htmlhttp://www.tkk7.com/kela/articles/64961.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/64961.htmlhttp://www.tkk7.com/kela/services/trackbacks/64961.html 鎽樿錛?/span> spring 涓ょ甯哥敤鐨勬敞鍏ユ柟寮忥紙 Type 2 Ioc 錛?/span> Type 3 Ioc 錛?/span>

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloBean.java

聽(tīng)

package com.kela.spring.ioc;

聽(tīng)

public class HelloBean {

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) private String name;

聽(tīng)聽(tīng)聽(tīng) private String helloWord;

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public HelloBean() {

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public HelloBean(String name, String helloWord) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.name = name;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.helloWord = helloWord;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public String getHelloWord() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return helloWord;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setHelloWord(String helloWord) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.helloWord = helloWord;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public String getName() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return name;

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) public void setName(String name) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.name = name;

聽(tīng)聽(tīng)聽(tīng) }

}

璇ョ▼搴忔枃浠朵腑璁蹭袱縐嶅父鐢ㄧ殑娉ㄥ叆鏂瑰紡鍐欏湪浜?jiǎn)涓璧楓?span lang="EN-US">

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) Beans-config_1.xml

聽(tīng)

<?xml version= "1.0" encoding= "GB2312" ?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >

聽(tīng)

<beans>

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) <!-- Type 3 Injection 閫氳繃鏋勯犳柟娉曪紙榪欓噷娉ㄦ剰鏋勯犳柟娉曚腑鍙傛暟鐨勯『搴忎繚鎸佷竴鑷達(dá)級(jí) -->

聽(tīng)聽(tīng)聽(tīng) <bean id= "helloBean_1" class= "com.kela.spring.ioc.HelloBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <constructor-arg index= "0" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> KangFeng </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </constructor-arg>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <constructor-arg index= "1" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> 浣犲ソ錛?/span> </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </constructor-arg>

聽(tīng)聽(tīng)聽(tīng) </bean>

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) <!-- Type2 Injection 閫氳繃 set 娉ㄥ叆娉?/span> -->

聽(tīng)聽(tīng)聽(tīng) <bean id= "helloBean_2" class= "com.kela.spring.ioc.HelloBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <property name= "name" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> Kela </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <property name= "helloWord" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <value> hello 錛?/span> </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng) </bean>

</beans>

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) TestClass.java

聽(tīng)

package com.kela.spring.ioc;

聽(tīng)

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

聽(tīng)

public class TestClass {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public void method_1() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) try {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) ApplicationContext context = new

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) FileSystemXmlApplicationContext("bin\\com\\kela\\spring\\ioc\\beans-config_1.xml");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloBean helloBean_1 = (HelloBean)context.getBean("helloBean_1");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println(" 鏋勯犳柟娉曟敞鍏ワ紙嬈㈣繋璇嶏級(jí)錛?span lang="EN-US">" + helloBean_1.getName() + ";" + helloBean_1.getHelloWord());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloBean helloBean_2 = (HelloBean)context.getBean("helloBean_2");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println("set 鏂規(guī)硶娉ㄥ叆錛堟榪庤瘝錛夛細(xì)" + helloBean_2.getName() + ";" + helloBean_2.getHelloWord());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) } catch (Exception e) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) System.out.println("[ERROR]" + e.getMessage());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng) public static void main(String[] args) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) TestClass testClass = new TestClass();

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) testClass.method_1();

聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

鍏充簬Constructor鍜?span lang="EN-US">Setter娉ㄥ叆鐨勫尯鍒叾瀹炲氨鏄錛屾槸瑕佸湪瀵硅薄寤烘椂鏄氨鍑嗗濂借祫婧愯繕鏄湪瀵硅薄寤虹珛濂戒箣鍚庯紝鍐嶄嬌鐢?span lang="EN-US">Setter鏂規(guī)硶鏉ヨ繘琛岃瀹氥?span lang="EN-US">

浠庡疄闄呬嬌鐢ㄨ搴︽潵鐪嬶紝涓涓傜敤浜庤緝鐭殑灞炴у垪錛屼竴涓傜敤浜庤緝闀跨殑灞炴у垪銆?b style="mso-bidi-font-weight: normal">



Kela 2006-08-22 09:36 鍙戣〃璇勮
]]>
kela鐨勭瑪璁?搴旂敤紼嬪簭妗嗘灦 ---- spring(1)http://www.tkk7.com/kela/articles/64725.htmlKelaKelaMon, 21 Aug 2006 02:23:00 GMThttp://www.tkk7.com/kela/articles/64725.htmlhttp://www.tkk7.com/kela/comments/64725.htmlhttp://www.tkk7.com/kela/articles/64725.html#Feedback0http://www.tkk7.com/kela/comments/commentRss/64725.htmlhttp://www.tkk7.com/kela/services/trackbacks/64725.html 娉細(xì)浠呬粎鏄釜浜哄涔?fàn)鎬葷粨鐨勭瑪璁幫紝渚嬪瓙鏉ヨ嚜浜庛?/span> Spring 鎶鏈墜鍐屻嬨併?/span> Expert One-On-One J2EE Development Without EJB 涓枃鐗堛嬨佷互鍙?qiáng)涓浜涚綉緇滄枃妗g瓑銆?/span>

聽(tīng)

1.聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 鍑嗗宸ヤ綔

浠庝笅杞界殑 spring 寮鍙戝寘 bin 鐩綍涓嬪皢鐩稿叧 lib 鍔犲叆鑷抽」鐩殑 ClassPath 涓?/span>

鎴戝姞鍏ョ殑 lib 鏂囦歡鏈夛細(xì)

spring.jar 錛堣繖涓枃浠跺寘鎷簡(jiǎn)鎵鏈?/span> Spring 鏀寔鐨勫姛鑳芥墍闇瑕佺殑綾伙紝鑰屼笉鍐嶉渶瑕佸姞鍏ヤ釜鍒殑 jar 鏂囦歡錛屽叧浜?/span> Spring 鍚勪釜鍏蜂綋鐨?/span> jar 鍖呯殑浣跨敤鑼冨洿錛屽彲鏌ヨ Spring 鐨勪腑鏂囨枃妗o級(jí)

commons-logging.jar 錛?/span> log4j.jar 錛?/span> log 鏃ュ織鎵闇錛?/span>

聽(tīng)

緙栧啓 log4j 閰嶇疆鏂囦歡 log4j.properties 錛屽皢鍏舵斁鍏?/span> src 涓嬶紝 log4j.properties 鍐呭濡備笅錛?/span>

log4j.rootLogger= ERROR, stdout

聽(tīng)

log4j.appender.stdout= org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout= org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern= %c {1} - %m%n

聽(tīng)

鎴戠殑宸ョ▼鐩綍緇撴瀯濡備笅錛?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)SpringProject錛堝伐紼嬪悕縐幫級(jí)
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) src
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log4j.properties
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) lib
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) commons-logging.jar
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) log4j-1.2.9.jar
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)spring.jar
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

2.聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 緙栧啓絎竴涓?/span> Spring 紼嬪簭

榪欐槸涓涓畝鍗曠殑 JavaBean 錛岀敤鏉ユ墦澹版嫑鍛箋?/span>

聽(tīng)

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) HelloBean.java

package com.kela.spring.helloword;

聽(tīng)

public class HelloBean {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) private String helloWord;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) public String getHelloWord() {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return helloWord;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) public void setHelloWord(String helloWord) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) this.helloWord = helloWord;

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }

}

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) beans-config.xml

聽(tīng)

<?xml version= "1.0" encoding= "GB2312" ?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >

聽(tīng)聽(tīng)聽(tīng)

<beans>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) <bean id= "helloBean"

class= "com.kela.spring.helloword.HelloBean" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) <property name= "helloWord" >

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) <value> 浣犲ソ錛?/span> Spring 鐖卞ソ鑰咃紒 </value>

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) </property>

聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) </bean>

</beans>

鈼?span style="FONT: 7pt 'Times New Roman'">聽(tīng)聽(tīng)聽(tīng)聽(tīng) TestClass.java

聽(tīng)

聽(tīng)聽(tīng)聽(tīng) package com.kela.spring.helloword;

聽(tīng)

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

聽(tīng)

public class TestClass {

聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) public static void main(String[] args) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) try {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) ApplicationContext context = new

FileSystemXmlApplicationContext("bin\\com\\kela\\spring\\helloword\\beans-config.xml");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) HelloBean helloBean = (HelloBean)context.getBean("helloBean");

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) System.out.println(" 鎵撳嵃嬈㈣繋璇嶏細(xì) " + helloBean.getHelloWord());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) } catch (Exception e) {

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) System.out.println("[ERROR]" + e.getMessage());

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) }

聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) }

}

3.聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 嫻嬭瘯

聽(tīng)

榪愯 TestClass.java 鏂囦歡錛屽唴瀹瑰涓嬶細(xì)

鎵撳嵃嬈㈣繋璇嶏細(xì)浣犲ソ錛?/span> Spring 鐖卞ソ鑰咃紒

4.聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) 瀛︿範(fàn)灝忕粨

聽(tīng)

閫氳繃閰嶇疆鐨勫艦寮忥紝瀵?/span> HelloBean.java 鏂囦歡涓睘鎬?/span> helloWord 娉ㄥ叆浜?jiǎn)涓孌墊枃浠訛紙浣犲ソ錛?/span> spring 鐖卞ソ鑰咃級(jí)錛?/span> HelloBean.java 鏂囦歡涓病鏈変換浣曚笌 Spring 鏈夊叧鐨勪笢瑗匡紝鍦ㄦ祴璇曠被涓 HelloBean 鐨勫0鏄庢槸鐢?/span> Spring 鑷姩瀹屾垚鐨勩?/span>



Kela 2006-08-21 10:23 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 97公开免费视频| 久久亚洲精品中文字幕| 免费高清A级毛片在线播放| 成人永久免费高清| 亚洲日韩精品国产3区| 97无码免费人妻超级碰碰夜夜| 亚洲一区无码中文字幕乱码| 97在线线免费观看视频在线观看| 亚洲大香人伊一本线| 国产免费一区二区三区| 欧洲乱码伦视频免费| 亚洲成人免费电影| 日韩免费一区二区三区在线播放 | 亚洲 暴爽 AV人人爽日日碰 | 国产成人高清亚洲| a级毛片免费观看在线| 18禁超污无遮挡无码免费网站国产| 亚洲乱码一区av春药高潮| 在线视频观看免费视频18| 国产 亚洲 中文在线 字幕| 性色av免费观看| 久久亚洲色WWW成人欧美| 国产v片免费播放| 一级A毛片免费观看久久精品 | 亚洲精品视频在线看| 一级**爱片免费视频| 亚洲中文字幕无码爆乳AV| a毛看片免费观看视频| 亚洲伊人tv综合网色| 免费在线观看视频网站| 亚洲熟妇丰满xxxxx| 免费**毛片在线播放直播| 五月婷婷免费视频| 久久九九亚洲精品| 99免费视频观看| 国产精品亚洲片夜色在线| 小小影视日本动漫观看免费| 人人公开免费超级碰碰碰视频| 亚洲精品乱码久久久久久久久久久久| 亚洲免费视频在线观看| 亚洲最大的黄色网|