您现在的位置是:首页 > 个人日记个人日记

spring-05-复杂数据类型注入

2019-02-03 18:08:28【个人日记】499人已围观

简介对复杂数据类型进行注入

复杂数据类型注入

创建一个Student对象

  1. package com.huangxin.spring.model;
  2. public class Student {
  3. private String name;
  4. private int age;
  5. @Override
  6. public String toString() {
  7. return "Student{" +
  8. "name='" + name + '\'' +
  9. ", age=" + age +
  10. '}';
  11. }
  12. public String getName() {
  13. return name;
  14. }
  15. public void setName(String name) {
  16. this.name = name;
  17. }
  18. public int getAge() {
  19. return age;
  20. }
  21. public void setAge(int age) {
  22. this.age = age;
  23. }
  24. }

复杂数据

  1. package com.huangxin.spring.model;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.Properties;
  5. import java.util.Set;
  6. public class CollectionBean {
  7. private List<String> list;
  8. private Set<String> set;
  9. private String array[] = new String[3];
  10. private Map<String, Object> map;
  11. private Properties properties;
  12. public List<String> getList() {
  13. return list;
  14. }
  15. public void setList(List<String> list) {
  16. this.list = list;
  17. }
  18. public Set<String> getSet() {
  19. return set;
  20. }
  21. public void setSet(Set<String> set) {
  22. this.set = set;
  23. }
  24. public String[] getArray() {
  25. return array;
  26. }
  27. public void setArray(String[] array) {
  28. this.array = array;
  29. }
  30. public Map<String, Object> getMap() {
  31. return map;
  32. }
  33. public void setMap(Map<String, Object> map) {
  34. this.map = map;
  35. }
  36. public Properties getProperties() {
  37. return properties;
  38. }
  39. public void setProperties(Properties properties) {
  40. this.properties = properties;
  41. }
  42. }

# 重点
xml配置
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.xsd">
<bean id="collectionBean" class="com.huangxin.spring.model.CollectionBean">
<property name="array">
<array>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</array>
</property>
<property name="list">
<list>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</list>
</property>
<property name="set">
<set>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</set>
</property>
<property name="map">
<map>
<entry key="k1" value="java"></entry>
<entry key="k2" value="android"></entry>
<entry key="k3" value-ref="student"></entry>
</map>
</property>
<property name="properties">
<props>
<prop key="k1">Java</prop>
<prop key="k2">C#</prop>
</props>
</property>
</bean>
<bean id="student" class="com.huangxin.spring.model.Student">
<property name="age" value="18"></property>
<property name="name" value="黄鑫"></property>
</bean>
</beans>

以上为大部分数据的注入,仔细看配置

Tags: JavaWeb  

评论区

    2024-12-21 19:32:38

    站长

    没有登录功能是为了方便大家留言,但留言接口现在被恶意攻击,将关闭留言接口,如有疑问,请联系我的QQ 1538933906/同微信


文章评论



给自个选个头像吧!






站点信息

  • 建站时间:   2019-01-31
  • 网站程序:   Tomcat+nginx
  • 文章统计:   44篇文章
  • 标签管理:   标签云
  • 微信公众号:  扫描二维码,联系我