点击这里给我发消息 点击这里给我发消息

Spring2.5注释驱动与基于注释的MVC

添加时间:2013-12-7
    相关阅读: VC

   Spring2.5
                   Foo.java FooStringname.
                  package com.tony.test;
    publicclass Foo {
            private String name;
                public String toStirng(){
                   return"Foo Name is :" + this.name;
                }
    Setget
    }
    2 Bar.java BarStringadd.
    package com.tony.test;
    publicclass Bar {
            private String add;
                public String toStirng(){
                   return"Bar Add is :" + this.add;
                }
    Setget
    }
    3 Main.java MainFooBar
    package com.tony.test;
    publicclass Main {
            private Foo foo;
            private Bar bar;
                public String toString(){
    return"Main : [" + this.foo.toStirng() +" "+ this.bar.toStirng() + "]";
                }
    Setget
    }
    4 Spring-config-beans.xml
            <bean id="main" class="com.tony.test.Main">
               <property name="foo" ref="foo"></property>
               <property name="bar" ref="bar"></property>
            </bean>

            <bean id="foo" class="com.tony.test.Foo">
               <property name="name" value="Foo"></property>
            </bean>
            <bean id="bar" class="com.tony.test.Bar">
               <property name="add" value="Bar"></property>
    </bean>
    5 Test.java TestSpringmain
    package com.tony.test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.
    ClassPathXmlApplicationContext;
    publicclass Test {
                publicstaticvoid main(String[] args) {
                     String[] locations = {"spring-config-beans.xml"};
    ApplicationContext ctx = new ClassPathXmlApplicationContext(locations);
                     Main main = (Main) ctx.getBean("main");
                     system.out.println(main);
                }
    }
    Test
    Main : [Foo Name is :Foo Bar Add is :Bar]
    1)Spring 2.5 package com.tony.test;

    import org.springframework.beans.factory.annotation.Autowired;

    publicclass Main {
               @Autowired
               private Foo foo;
               @Autowired
               private Bar bar;

               public String toString(){
 

[1] [2] [3] 下一页

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册