spring注入不同数据类型
1.先来个实体类,里面包含各种数据类型,其他代码参考
1 package com.domain; 2 3 import java.util.List; 4 import java.util.Map; 5 import java.util.Properties; 6 import java.util.Set; 7 8 /** 9 * 10 * @author Mr 11 * 各种各样的数据类型 12 */ 13 public class TestEntity { 14 //特殊的类型1 15 private String specialCharacter1; 16 //特殊的类型2 17 private String specialCharacter2; 18 //javaBean类型 19 private User innerBean; 20 //List类型 21 private Listlist; 22 //数组类型 23 private String [] array; 24 //Set集合类型 25 private Set set; 26 //Map类型 27 private Map map; 28 //properties 29 private Properties props; 30 //空字符串 31 private String emptyValue; 32 //空字符串 33 private String nullValue="init value"; 34 public String getSpecialCharacter1() { 35 return specialCharacter1; 36 } 37 public void setSpecialCharacter1(String specialCharacter1) { 38 this.specialCharacter1 = specialCharacter1; 39 } 40 public String getSpecialCharacter2() { 41 return specialCharacter2; 42 } 43 public void setSpecialCharacter2(String specialCharacter2) { 44 this.specialCharacter2 = specialCharacter2; 45 } 46 public User getInnerBean() { 47 return innerBean; 48 } 49 public void setInnerBean(User innerBean) { 50 this.innerBean = innerBean; 51 } 52 public List getList() { 53 return list; 54 } 55 public void setList(List list) { 56 this.list = list; 57 } 58 public String[] getArray() { 59 return array; 60 } 61 public void setArray(String[] array) { 62 this.array = array; 63 } 64 public Set getSet() { 65 return set; 66 } 67 public void setSet(Set set) { 68 this.set = set; 69 } 70 public Map getMap() { 71 return map; 72 } 73 public void setMap(Map map) { 74 this.map = map; 75 } 76 public Properties getProps() { 77 return props; 78 } 79 public void setProps(Properties props) { 80 this.props = props; 81 } 82 public String getEmptyValue() { 83 return emptyValue; 84 } 85 public void setEmptyValue(String emptyValue) { 86 this.emptyValue = emptyValue; 87 } 88 public String getNullValue() { 89 return nullValue; 90 } 91 public void setNullValue(String nullValue) { 92 this.nullValue = nullValue; 93 } 94 95 //来个方法显示相关 96 public void showValue(){ 97 98 System.out.println("特殊的类型1:"+this.specialCharacter1); 99 System.out.println("特殊的类型1:"+this.specialCharacter2);100 System.out.println("javaBean类型:"+this.innerBean.getUname());101 System.out.println("List类型:"+this.list);102 System.out.println("数组类型:"+this.array[0]);103 System.out.println("Set集合类型:"+this.set);104 System.out.println("Map类型:"+this.map);105 System.out.println("properties类型:"+this.props);106 System.out.println("空字符串类型:"+this.emptyValue);107 System.out.println("空字符串类型:"+this.nullValue);108 }109 110 }
2.写spring配置文件
1 28 9 10 11 84 85 86 8712 14 1513 16 18 19P&G 1720 21 27 2822 2623 25张三丰 2429 35 3630
34乒乓球 31排球球 32羽毛球 3337 42 4338
41苹果 39香蕉 4044 49 5045
48电视机 46冰柜 4751 67 68 6970 75 7671 74北京 72上海 7377 79 8078 81 8382
3.写测试类
1 package com.test; 2 3 import org.springframework.context.ApplicationContext; 4 import org.springframework.context.support.ClassPathXmlApplicationContext; 5 6 import com.biz.IUserBiz; 7 import com.domain.TestEntity; 8 import com.domain.User; 9 10 /**11 * 12 * @author Mr13 * aop测试类14 */15 public class Test {16 17 public static void main(String[] args) {18 //解析配置文件19 ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");20 21 TestEntity te = (TestEntity) ac.getBean("entitys");22 te.showValue();23 }24 25 }
4.效果图