1 package com.it.dao.impl;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import com.it.dao.SayHell;
7
8 /**
9 * Spring如何知道setter方法?如何将值注入进去的呢?其实方法名是要遵守约定的,setter注入的方法名要遵循“JavaBean getter/setter 方法命名约定”:
10 *
11 JavaBean:是本质就是一个POJO类,但具有一下限制:
12 该类必须要有公共的无参构造器,如public HelloImpl4() {};
13 属性为private访问级别,不建议public,如private String message;
14 属性必要时通过一组setter(修改器)和getter(访问器)方法来访问;
15 setter方法,以“set” 开头,后跟首字母大写的属性名,如“setMesssage”,简单属性一般只有一个方法参数,方法返回值通常为“void”;
16 getter方法,一般属性以“get”开头,对于boolean类型一般以“is”开头,后跟首字母大写的属性名,如“getMesssage”,“isOk”;
17 还有一些其他特殊情况,比如属性有连续两个大写字母开头,如“URL”,则setter/getter方法为:“setURL”和“getURL”,其他一些特殊情况请参看“Java Bean”命名规范。
18 * @return
19 */
20 public class SayHelloImpl4 implements SayHell {
21
22 private List<String> listValue;
23
24 private Map<String,Integer> mapValue;
25
26 private int fistBleed;
27
28 private Map<String,SayHelloImpl4> firstMap;
29
30
31
32
33 public Map<String, SayHelloImpl4> getFirstMap() {
34 return firstMap;
35 }
36
37
38 public void setFirstMap(Map<String, SayHelloImpl4> firstMap) {
39 this.firstMap = firstMap;
40 }
41
42
43 public int getFistBleed() {
44 return fistBleed;
45 }
46
47
48 public void setFistBleed(int fistBleed) {
49 this.fistBleed = fistBleed;
50 }
51
52
53 public List<String> getListValue() {
54 return listValue;
55 }
56
57
58 public void setListValue(List<String> listValue) {
59 this.listValue = listValue;
60 }
61
62
63
64 public Map<String, Integer> getMapValue() {
65 return mapValue;
66 }
67
68
69 public void setMapValue(Map<String, Integer> mapValue) {
70 this.mapValue = mapValue;
71 }
72
73
74 @Override
75 public void sayHello() {
76 int i=1;
77 for (String string : listValue) {
78 System.out.println(i+"、"+string);
79 i++;
80 }
81
82 }
83
84 public void sayMapGood(){
85 int size = mapValue.size();
86 if(size!=0){
87 for(int a=1; a<=size ;a++){
88 System.out.println(a+"、"+mapValue.get(String.valueOf(a)));
89 }
90 }
91 }
92
93 public void sayMapGood2(){
94 int size = firstMap.size();
95 if(size!=0){
96 System.out.println(firstMap.get("1").fistBleed);
97 }
98 }
99
100 }