欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring 简单属性注入

程序员文章站 2022-05-24 10:48:12
...
代码备份而已。
package com.clover.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class User {
private String name;
private int age;
private String sex;
private String addr;
private Map<String, String> school = new HashMap<String, String>();
private List<String> list = new ArrayList<String>();
private Properties prop = new Properties();

public User() {
}

public User(String sex, int age) {
this.sex = sex;
this.age = age;
}

public User(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public String getAddr() {
return addr;
}

public void setAddr(String addr) {
this.addr = addr;
}

public Map<String, String> getSchool() {
return school;
}

public void setSchool(Map<String, String> school) {
this.school = school;
}

public List<String> getList() {
return list;
}

public void setList(List<String> list) {
this.list = list;
}

public Properties getProp() {
return prop;
}

public void setProp(Properties prop) {
this.prop = prop;
}

@Override
public String toString() {
return "User's info\nname:" + this.name + ";age:" + this.age + ";sex:" +
this.sex + ";addr:" + this.addr +
"\nschool:" + school.toString() + "\nList:" + list.toString() +
"\nprop:" + prop.toString();
}

// 简单输出
public void hello() {
System.out.println("Hello,world!!!");
}
}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd"
>
<bean id="user" class="com.clover.bean.User">
<constructor-arg name="age" index="1" type="int" value="26" />
<constructor-arg name="sex" index="0" type="java.lang.String" value="boy" />
<property name="name" value="clover"/>
<property name="addr" value="郑州" />
<property name="school">
<map>
<entry key="name" value="河南工业大学" />
<entry key="date" value="2010" />
</map>
</property>
<property name="list">
<list>
<value>hhh</value>
<value>fuck</value>
</list>
</property>
<property name="prop">
<props>
<prop key="first">11111111</prop>
<prop key="secod">22222222</prop>
</props>
</property>
</bean>
</beans>
相关标签: spring xml java