<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 147  文章 - 71  trackbacks - 0
    <2013年3月>
    242526272812
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    常用鏈接

    留言簿(1)

    隨筆分類(146)

    隨筆檔案(147)

    文章分類(28)

    文章檔案(28)

    喜歡的Blog

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    步驟:

    第一步:建工程
       File -> New -> Project ->Web Project,"Project Name":MySpringTest,然后"Finish";

    第二步:導入spring包
       選中MySpringTest,右擊,MyEclipse -> Add Spring Capabilities……,都默認即可;

    第三步:
       建立項目所需類;MySpringTest -> src -> New ...(以下三個都這樣建)Spring 的開發沒法自動生成 Bean, 這里大家只好手工來寫了, 也很簡單。

    1、接口Action:(MySpringTest -> src -> New -> interface ,取名為Action)

    public interface Action {
        
    public String execute(String str);
    }

    2、實現接口Action的類UpperAction:(將其 message 屬性與輸入字符串相連接,并返回其大寫形式。)
       (MySpringTest -> src -> New -> class ,取名為UpperAction)

    public class UpperAction implements Action {
        
    private String message;

        
    public String getMessage() {
            
    return message;
        }

        
    public void setMessage(String message) {
            
    this.message = message;
        }

        
    public String execute(String str) {
            
    return (getMessage() + str).toUpperCase();
        }
    }

    3、實現接口Action的類LowerAction:

    (將其 message 屬性與輸入字符串相連接,并返回其小寫形式。)
       (MySpringTest -> src -> New -> class ,取名為LowerAction) 

    public class LowerAction implements Action {
        
    private String message;

        
    public String getMessage() {
            
    return message;
        }

        
    public void setMessage(String message) {
            
    this.message = message;
        }

        
    public String execute(String str) {
            
    return (getMessage() + str).toLowerCase();
        }
    }
    4、做測試用的SimpleTest類:
    (MySpringTest -> src -> New -> class ,取名為SimpleTest)
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;

    public class SimpleTest {
        
    public static void main(String args[]) {
            SimpleTest test 
    = new SimpleTest();
            test.testQuickStart();
        }

        
    public void testQuickStart() {
            ApplicationContext ctx 
    = new FileSystemXmlApplicationContext(
                    
    "src/applicationContext.xml");
            Action action 
    = (Action) ctx.getBean("action1");
            System.out.println(action.execute(
    "Rod Johnson"));
            action 
    = (Action) ctx.getBean("action2");
            System.out.println(action.execute(
    "jeckj"));
        }
    }
    5、配置applicationContext.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

        
    <description>Spring Quick Start</description>

        
    <!--該處bean中的name值必須是 其對應的class中的私有成員名
        
    -->
        
    <bean id="action1" class="UpperAction">
            
    <property name="message">
                
    <value>HeLLo</value>
            
    </property>
        
    </bean>

        
    <bean id="action2" class="LowerAction">
            
    <property name="message">
                
    <value>HeLLo</value>
            
    </property>
        
    </bean>
    </beans>
    5、在WEB-INF/class 目錄下建立一個log4j.propertie
    log4j.rootLogger=ERROR,stdout 
    log4j.appender.stdout
    =org.apache.log4j.ConsoleAppender 
    log4j.appender.stdout.layout
    =org.apache.log4j.PatternLayout 
    log4j.appender.stdout.layout.ConversionPattern
    =%d %5p (%F:%L) - %m%n 
    第四步:調試
    雙擊 Package Explorer 下 MySpringTest/src/TestAction.java 打開源代碼,點擊菜單 Run -> Run As -> 1. Java Application, 如果沒有錯誤的話將會出現如下
    HELLOROD JOHNSON
    hellojeckj
    posted on 2013-03-27 20:18 飛翔天使 閱讀(351) 評論(0)  編輯  收藏 所屬分類: Spring

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲爆乳无码专区| 亚洲精品97久久中文字幕无码| 亚洲区小说区图片区QVOD| 免费夜色污私人影院网站电影| 四虎影院永久免费观看| 看全免费的一级毛片| 国产在线不卡免费播放| 特级毛片aaaa免费观看| 亚洲国产成人乱码精品女人久久久不卡| 亚洲欧美精品午睡沙发| 国产老女人精品免费视频| 精品国产日韩亚洲一区91| 免费a级黄色毛片| 国产福利电影一区二区三区,免费久久久久久久精 | 小说专区亚洲春色校园| 又粗又黄又猛又爽大片免费| 人妻18毛片a级毛片免费看| 中文字幕精品亚洲无线码二区| 你是我的城池营垒免费观看完整版| 国产亚洲精品美女久久久| 最近免费字幕中文大全视频| 国产成人精品日本亚洲网址| 精品国产免费一区二区| 一日本道a高清免费播放| 亚洲国产精品特色大片观看完整版| 91麻豆国产免费观看| 亚洲中文字幕无码爆乳| 四虎永久免费观看| 三年片免费高清版| 亚洲国产精品成人精品软件| 色视频色露露永久免费观看| h视频在线观看免费| 久久亚洲国产精品成人AV秋霞 | 久久亚洲精品人成综合网| 亚洲视频免费观看| 国产精品亚洲精品日韩动图| 亚洲精品无码永久中文字幕| 2021久久精品免费观看| 人妻免费久久久久久久了| 亚洲女人初试黑人巨高清| 亚洲AⅤ无码一区二区三区在线|