zoukankan      html  css  js  c++  java
  • 我的第六个java程序 spring-bean

    配置文件 Beans.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-3.0.xsd">
     
           <bean id="helloWorld" class="com.importnew.HelloWorld">
               <property name="message" value="棒棒哒"/>
               <property name="xingrongci" value="夸奖"/>
           </bean>
           
           
     
        </beans>

    主程序 MainApp.java

    package com.importnew;
     
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
     
    public class MainApp {
        public static void main(String[] args) {
     
            ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
     
            HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
            obj.printMessage();
            
    
            
        }
    }

    HelloWorld.java

    package com.importnew;
     
    public class HelloWorld {
     
        private String message;
        private String xingrongci;//私有
     
        public void setMessage(String message){
            this.message  = message;
        }
     
        public String getMessage(){
            return this.message;
        }
        
        /**设置形容词为此类的一个属性**/
        public void setXingrongci(String xingrongci){
            this.xingrongci  = xingrongci;
        }
     
        public String getXingrongci(){
            return this.xingrongci;
        }
        
     
        public void printMessage(){
            System.out.println("小明" + message + "
    ");
            System.out.println(message + "小王"+ "
    ");
            System.out.println(message + "是一个形容词" + "
    ");
            System.out.println("说某人" + message +"有可能是"+xingrongci+"的意思 "+"
    ");
            System.out.println(message + "小王和小明" + "
    ");
        }
    }

    效果

  • 相关阅读:
    eventbus 备注
    Retrofit 备注
    RxJava 备注
    dagger2 备注
    JVM 备注
    UI控件(UIPickerView)
    Android 知识杂记(MVP模式)
    UI控件(UIToolbar)
    UI控件(UIAlertController)
    UI控件(UIScrollView)
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5002951.html
Copyright © 2011-2022 走看看