重拾Spingmvc之路---------《6》--------注入复杂类型属性

1.P名称空间注入(少用):

代码很简单:

public class SteClass {

	private String nameSet;

	public void setNameSet(String nameSet) {
		this.nameSet = nameSet;
	}
	public void testSet(){
		System.out.println("setTest===="+nameSet);
	}
	
}
 xmlns:p="http://www.springframework.org/schema/p"
 <bean id="name" class="ioc.SteClass" p:nameSet="小谢"></bean>
@Test
	public void test4(){
		ApplicationContext con=new ClassPathXmlApplicationContext("mapper/spring.xml");
		SteClass us=(SteClass) con.getBean("name");
		us.testSet();
	}

2. 数组:

3. list集合:

4.map集合:

5.properties 《键值对》类型:

代码如下

public class Person {

	private String[]arras;
	private  List<String> list;
	private Map<String,String> map;
	private Properties properties;
	public void setArras(String[] arras) {
		this.arras = arras;
	}
	
	public void setList(List<String> list) {
		this.list = list;
	}
	
	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	
	public void setProperties(Properties properties) {
		this.properties = properties;
	}
	
	public void test1(){
		System.out.println("arras=="+arras);
		System.out.println("arras=="+arras[0]);
		System.out.println("map=="+map);
		System.out.println("list=="+list);
		System.out.println("properties=="+properties);
	}
	
  
  
       <!-- 注入复杂属性值 -->
       <bean id="persion" class="ioc.Person">
       <!-- 数组 -->
       <property name="arras" >
          <list>
            <value>小谢</value>
            <value>小猫</value>
            <value>小猪</value>
            <value>小狗</value>
          </list>
       </property>
       <!-- 集合 -->
       <property name="list" >
          <list>
            <value>老谢</value>
            <value>老猫</value>
            <value>老猪</value>
            <value>老狗</value>
          </list>
       </property>
       <!-- map -->
       <property name="map" >
         <map>
           <entry key="1" value="小鸡"></entry>
           <entry key="2" value="小谢"></entry>
           <entry key="3" value="小鸭"></entry>
           <entry key="4" value="小虫"></entry>
         </map>
       </property>
       
       <!-- properties-->
          <property name="properties">
             <props>
                <prop key="driverclass">class.mysql.jdbc.Driver</prop>
                <prop key="username">root</prop>
             </props>
          </property>
       </bean>
@Test
	public void test5(){
		ApplicationContext con=new ClassPathXmlApplicationContext("mapper/spring.xml");
		Person us=(Person) con.getBean("persion");
		us.test1();
		
	}
	



       
         



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值