zoukankan      html  css  js  c++  java
  • Spirng setter 注入简单

    1.      提供相应要注入的属性

    //setter注入
    public class Bean2 {
    	private String name;
    	private Integer age;
    	// 提供要注入的属性相应的setter方法
    	public void setName(String name) {
    		this.name = name;
    	}
    	public void setAge(Integer age) {
    		this.age = age;
    	}
    	public void show() {
    		System.out.println("bean2:" + name + "," + age);
    	}
    }


    2.      为每一个要注入的属性提供相应的标准封装setter方法


    3.      在配置中为Bean指定要注入的属性,使用property元素name=“属性”value=“值”

    	<!-- setter注入 -->
    	<bean id="bean2" class="com.hao947.bean.Bean2">
    		<property name="name" value="hao947"/>
    		<property name="age" value="947"></property>
    	</bean>


    <propertyname = “属性” value=”值”>


    測试

    	@Test
    	public void show_setter() {
    		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    		Bean2 bean2 = (Bean2) ac.getBean("bean2");
    		bean2.show();
    	}


  • 相关阅读:
    树状数组基础
    Color the ball HDU1556
    敌兵布阵 HDU1166
    线段树基础
    T9 HDU1298
    7-6 Bandwidth UVA140
    测试方法:
    测试过程:
    爬天极网美女图片缩略图:
    爬天极网美女预览图版一:
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5069408.html
Copyright © 2011-2022 走看看