一、概念
项目管理框架,也是一套JAVAEE解决方案;
优秀的设计模式组合;
是一款将众多框架整合的产品
二、架构促成
核心技术:依赖注入,事件,资源,验证,数据绑定,类型转换,I18N(i开头,N结尾,中间18个字符), SpEL(Spring表达式语言),AOP(面向切面编程);
测试:模拟对象,TestContext框架,Spring MVC测试,WebTestClient。
数据访问:事物,DAO,JDBC,ORM
继承:远程处理,JMS,JCA,JMX,电子邮件,任务,调度,缓存。
语言:Kotlin,Groovy,动态语言
三、pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
<groupId>org.example</groupId>
<artifactId>SpringTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.6.RELEASE</version>
</dependency>
</dependencies>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 四、(IOC &DI)控制反转&依赖注入: bean节点:
id:指定bean的id,可以通过该id得到该bean的对象。
class:指明该类的路径,要求该bean类有 无参构造器。
scope:特指作用范围:
1、singleton 单例模式(默认);
2、prototype 多实例模式;
3、request:web请求;
4、session:web会话。
第一种(利用name):
poto实体:
@Data
public class User {
private int uid;
private String username;
private String password;
private int age;
private String telephone;
private Brand brand;
public User() {
}
public User(int uid, String username, String password, int age, String telephone) {
this.uid = uid;
this.username = username;
this.password = password;
this.age = age;
this.telephone = telephone;
}
public User(int uid, String username, String password, int age, String telephone, Brand brand) {
this.uid = uid;
this.username = username;
this.password = password;
this.age = age;
this.telephone = telephone;
this.brand = brand;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Brand getBrand() {
return brand;
}
public void setBrand(Brand brand) {
this.brand = brand;
}
@Override
public String toString() {
return "User{" +
"uid=" + uid +
", username='" + username + '\'' +
", password='" + password + '\'' +
", age=" + age +
", telephone='" + telephone + '\'' +
", brand=" + brand +
'}';
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
beans.xml
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“Beans.xml”);
User user = applicationContext.getBean(“user”,User.class);
System.out.println(user.toString());
System.out.println();
1
2
3
4
bean
constructor-arg :调用带参构造器
property :调用Set方法
value:值
ref :引用
第二种(直接创建):
<bean id="user2" class="pojo.User">
<constructor-arg value="2"/>
<constructor-arg value="橘梨纱"/>
<constructor-arg value="123456"/>
<constructor-arg value="21"/>
<constructor-arg value="15122223333"/>
<property name="brand" ref="brand"/>
</bean>
1
2
3
4
5
6
7
8
9
代码简单
可读性较差
第三种( 利用下标):
<bean id="user3" class="pojo.User">
<constructor-arg index="0" value="3"/>
<constructor-arg index="1" value="三上悠亚"/>
<constructor-arg index="2" value="123456"/>
<constructor-arg index="3" value="25"/>
<constructor-arg index="4" value="15122312232"/>
<property name="brand" ref="brand"/>
</bean>
1
2
3
4
5
6
7
8
9
第四种(利用类型):
<bean id="user4" class="pojo.User">
<constructor-arg type="java.lang.String" value="樱井莉亚"/>
<constructor-arg type="int" value="4"/>
<constructor-arg type="int" value="27"/>
<constructor-arg type="java.lang.String" value="12345"/>
<constructor-arg type="java.lang.String" value="15199987777"/>
<property name="brand" ref="brand"/>
</bean>
1
2
3
4
5
6
7
8
9
相同类型 按先后顺序.
第五种(schema代理):
<bean id="user5" class="pojo.User" pp:uid="5" pp:username="深田咏美" pp:password="12345" pp:age="25" pp:telephone="13533229988"/>
1 2 3 4 5 6 7 8 9
可读性较差
数组
实体类
package pojo;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Array {
private String[] array;
private List list;
private Set set;
private Map<Object, Object> map;
@Override
public String toString() {
return "Array{" +
"array=" + Arrays.toString(array) +
", list=" + list +
", set=" + set +
", map=" + map +
'}';
}
public String[] getArray() {
return array;
}
public void setArray(String[] array) {
this.array = array;
}
public List<Object> getList() {
return list;
}
public void setList(List<Object> list) {
this.list = list;
}
public Set<Integer> getSet() {
return set;
}
public void setSet(Set<Integer> set) {
this.set = set;
}
public Map<Object, Object> getMap() {
return map;
}
public void setMap(Map<Object, Object> map) {
this.map = map;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
ArrayBean.xml
<property name="array">
<array>
<value>苍井空</value>
<value>小泽玛利亚</value>
<value>泷泽萝拉</value>
<value>武藤兰</value>
<value>麻美由真</value>
</array>
</property>
————————————————
版权声明:本文为CSDN博主「深田咏美脑残粉」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/llp705/article/details/107458264