zoukankan      html  css  js  c++  java
  • Spring Mvc 实例

    
    
    package com.spring.test;
    
    public interface IHelloMessage {
        public String sayHello();
    
    }
    
    
    
    package com.spring.test;
    
    public class HelloChina implements IHelloMessage {
    
        public String sayHello() {
            // TODO Auto-generated method stub
            return "你好中国!";
        }
    
    }
    package com.spring.test;
    
    public class HelloWorld implements IHelloMessage {
    
        public String sayHello() {
            // TODO Auto-generated method stub
            return "Hello World!";
        }
    
    }
    package com.spring.test;
    
    public class Person {
        private IHelloMessage helloMessage;
    
        public IHelloMessage getHelloMessage() {
            return helloMessage;
        }
    
        public void setHelloMessage(IHelloMessage helloMessage) {
            this.helloMessage = helloMessage;
        }
    
        public String sayHello() {
            // TODO Auto-generated method stub
            return this.helloMessage.sayHello();
        }
    
    }
    package com.spring.test;
    
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.FileSystemResource;
    import org.springframework.core.io.Resource;
    
    public class Main {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            Resource resource = new FileSystemResource("helloMessage.xml");
            @SuppressWarnings("deprecation")
            BeanFactory factory = new XmlBeanFactory(resource);
            Person person = (Person) factory.getBean("person");
            String string = person.sayHello();
            System.out.println("please to say" + string);
    
        }
    
    }
    <?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.xsd">
    
        <bean id="helloWorld" class="com.spring.test.HelloWorld">
        </bean>
        <bean id="helloChina" class="com.spring.test.HelloChina">
        </bean>
        <bean id="person" class="com.spring.test.Person">
            <property name="helloMessage" ref="helloChina" />
        </bean>
    
    </beans>
  • 相关阅读:
    准备 FRM 考试——方法、工具与教训
    930. 和相同的二元子数组 前缀和
    1906. 查询差绝对值的最小值 前缀和
    剑指 Offer 37. 序列化二叉树 二叉树 字符串
    815. 公交路线 BFS
    518. 零钱兑换 II dp 完全背包
    1049. 最后一块石头的重量 II dp
    5779. 装包裹的最小浪费空间 二分
    5778. 使二进制字符串字符交替的最少反转次数 字符串 滑动窗口
    474. 一和零 dp
  • 原文地址:https://www.cnblogs.com/silianbo/p/4721629.html
Copyright © 2011-2022 走看看