java

package cn.ioc.student;

import java.util.List;
import java.util.Map;
import java.util.Set; public class Student {
private String name;
private Address addr;
private String[] books;
private List<String> testlist;
private Map<String,String> cards;
private Set<String> games;
private String wife; public String getWife() {
return wife;
} public void setWife(String wife) {
this.wife = wife;
} public Set<String> getGames() {
return games;
} public void setGames(Set<String> games) {
this.games = games;
} public List<String> getTestlist() {
return testlist;
} public void setTestlist(List<String> testlist) {
this.testlist = testlist;
} public Map<String, String> getCards() {
return cards;
} public void setCards(Map<String, String> cards) {
this.cards = cards;
} public String[] getBooks() {
return books;
} public void setBooks(String[] books) {
this.books = books;
} //-------------------------------------------------
public Address getAddr() {
return addr;
} public void setAddr(Address addr) {
this.addr = addr;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
//show
public void show(){
System.out.print("---我叫"+name+",---我住在"+addr.getAddr()+"---我爱看的书有"); for(int i=0;i<books.length;i++){
System.out.print(books[i]+",");
}
System.out.println("---list"+testlist);
System.out.println("---map="+cards);
System.out.println("---set="+games);
System.out.println("---wife老婆=");
}
}

address.class

package cn.ioc.student;

public class Address {
private String addr; public String getAddr() {
return addr;
} public void setAddr(String addr) {
this.addr = addr;
} }

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
https://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- ioc -->
<bean id="address" class="cn.ioc.student.Address">
<property name="addr" value="beijing"></property>
</bean>
<!-- ref引用注入 -->
<bean id="student" class="cn.ioc.student.Student">
<property name="name" value="shangren"></property>
<property name="addr" ref="address"></property>
<!-- 数组注入 -->
<property name="books">
<array>
<value>书1</value>
<value>书2</value>
<value>书3</value>
</array>
</property>
<!-- list注入 -->
<property name="testlist">
<list>
<value>排球</value>
<value>足球</value>
<value>篮球</value>
</list>
</property>
<!-- map -->
<property name="cards">
<map>
<entry key="中国银行" value="1997081100"></entry>
<entry>
<key><value>建设银行</value></key>
<value>110110110</value>
</entry>
</map>
</property>
<!-- set -->
<property name="games">
<set>
<value>dota</value>
<value>cs</value>
<value>cs</value>
</set>
</property>
<!-- 空 null -->
<property name="wife">
<null></null>
</property>
</bean>
</beans>

test.class

package cn.ioc.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.ioc.student.Student; public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
Student stu = (Student) ac.getBean("student");
stu.show();
}
}

结果

最新文章

  1. python学习之day4,函数
  2. Canvas 与 Paint 类的 使用
  3. 01 Apache Solr:提升检索体验 为什么是Solr
  4. DTMF的原理分析
  5. javascript性能优化总结二(转载)
  6. 转载 -- 如何判断Javascript对象是否存在
  7. 百度搜索词&amp;淘宝搜索词 接口实现
  8. SQL编程之高级查询(子查询)以及注意事项
  9. 1106c语言语法树
  10. Python 融于ASP框架
  11. 读《C# 和 Java 的比较》有感
  12. MySql索引的优缺点
  13. ACM2035_(递归法求幂)
  14. Wireshark抓包、过滤器
  15. OC -- 第一个类
  16. java学习笔记——IO部分(遍历文件夹)
  17. 编程之美2.18 数组分割 原创解O(nlogn)的时间复杂度求解:
  18. SVN插件和Tomcat插件地址
  19. ffmpeg中AVBuffer的实现分析
  20. Innodb IO优化-配置优化

热门文章

  1. vue-cli3.0 gui初体验
  2. 精确计算微信小程序scrollview高度,全机型适配
  3. mysql建立ssl安全连接的配置
  4. unittest 管理接口用例(数据分离-读取excel)
  5. postman(参数化)
  6. Linux之进程管理工具supervisor
  7. zabbix分布式安装全过程
  8. 基于3D NAND层差异的固态盘请求调度算法研究立项 报告
  9. 多线程高并发编程(8) -- Fork/Join源码分析
  10. 你应该知道的Python3.6、3.7、3.8新特性