Skip to content

Commit 9471acd

Browse files
committed
upload
1 parent 2a798cf commit 9471acd

23 files changed

Lines changed: 1679 additions & 0 deletions

javaframework/spring/第三节课/spring_study2/.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javaframework/spring/第三节课/spring_study2/.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javaframework/spring/第三节课/spring_study2/.idea/workspace.xml

Lines changed: 684 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.mashibing</groupId>
8+
<artifactId>spring_study</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<dependencies>
12+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
13+
<dependency>
14+
<groupId>org.springframework</groupId>
15+
<artifactId>spring-context</artifactId>
16+
<version>5.2.3.RELEASE</version>
17+
</dependency>
18+
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
19+
<dependency>
20+
<groupId>com.alibaba</groupId>
21+
<artifactId>druid</artifactId>
22+
<version>1.1.21</version>
23+
</dependency>
24+
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
25+
<dependency>
26+
<groupId>mysql</groupId>
27+
<artifactId>mysql-connector-java</artifactId>
28+
<version>5.1.48</version>
29+
</dependency>
30+
31+
32+
</dependencies>
33+
34+
</project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.mashibing.bean;
2+
3+
public class Address {
4+
private String province;
5+
private String city;
6+
private String town;
7+
8+
public Address() {
9+
System.out.println("address被创建");
10+
}
11+
12+
public String getProvince() {
13+
return province;
14+
}
15+
16+
public void setProvince(String province) {
17+
this.province = province;
18+
}
19+
20+
public String getCity() {
21+
return city;
22+
}
23+
24+
public void setCity(String city) {
25+
this.city = city;
26+
}
27+
28+
public String getTown() {
29+
return town;
30+
}
31+
32+
public void setTown(String town) {
33+
this.town = town;
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return "Address{" +
39+
"province='" + province + '\'' +
40+
", city='" + city + '\'' +
41+
", town='" + town + '\'' +
42+
'}';
43+
}
44+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.mashibing.bean;
2+
3+
import org.springframework.beans.BeansException;
4+
import org.springframework.beans.factory.config.BeanPostProcessor;
5+
6+
public class MyBeanPostProcessor implements BeanPostProcessor {
7+
/**
8+
* 在每一个对象的初始化方法前面执行
9+
* @param bean 表示创建的具体对象
10+
* @param beanName 表示bean的id属性
11+
* @return
12+
* @throws BeansException
13+
*/
14+
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
15+
System.out.println("postProcessBeforeInitialization:"+beanName);
16+
return bean;
17+
}
18+
19+
/**
20+
* 在每一个对象的初始化方法后面执行
21+
* @param bean
22+
* @param beanName
23+
* @return
24+
* @throws BeansException
25+
*/
26+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
27+
System.out.println("postProcessAfterInitialization:"+beanName);
28+
return bean;
29+
}
30+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.mashibing.bean;
2+
3+
import java.util.*;
4+
5+
public class Person {
6+
private int id;
7+
private String name;
8+
private Integer age;
9+
private String gender;
10+
private String[] hobbies;
11+
private Address address;
12+
13+
private List<Address> lists;
14+
private Set<String> sets;
15+
private Map<String,Object> maps;
16+
// private Properties properties;
17+
18+
public Person() {
19+
System.out.println("person被创建");
20+
}
21+
22+
public Person(Address address) {
23+
this.address = address;
24+
}
25+
26+
public Person(int id, String name, Address address) {
27+
this.id = id;
28+
this.name = name;
29+
this.address = address;
30+
}
31+
32+
public Person(int id, String name, Integer age, String gender) {
33+
this.id = id;
34+
this.name = name;
35+
this.age = age;
36+
this.gender = gender;
37+
}
38+
39+
40+
public Person(int id, String name, Integer age) {
41+
this.id = id;
42+
this.name = name;
43+
this.age = age;
44+
System.out.println("age......");
45+
}
46+
public Person(int id, String name, String gender) {
47+
this.id = id;
48+
this.name = name;
49+
this.gender = gender;
50+
System.out.println("gender.....");
51+
}
52+
53+
public void init(){
54+
//编写N行逻辑代码完成初始化功能
55+
System.out.println("person对象初始化完成");
56+
}
57+
58+
public void destory(){
59+
System.out.println("person对象被销毁");
60+
}
61+
62+
public int getId() {
63+
return id;
64+
}
65+
66+
public void setId(int id) {
67+
this.id = id;
68+
}
69+
70+
public String getName() {
71+
return name;
72+
}
73+
74+
public void setName(String name) {
75+
this.name = name;
76+
}
77+
78+
public Integer getAge() {
79+
return age;
80+
}
81+
82+
public void setAge(Integer age) {
83+
this.age = age;
84+
}
85+
86+
public String getGender() {
87+
return gender;
88+
}
89+
90+
public void setGender(String gender) {
91+
this.gender = gender;
92+
}
93+
94+
public String[] getHobbies() {
95+
return hobbies;
96+
}
97+
98+
public void setHobbies(String[] hobbies) {
99+
this.hobbies = hobbies;
100+
}
101+
102+
public Address getAddress() {
103+
return address;
104+
}
105+
106+
public void setAddress(Address aaddress) {
107+
this.address = aaddress;
108+
}
109+
110+
public List<Address> getLists() {
111+
return lists;
112+
}
113+
114+
public void setLists(List<Address> lists) {
115+
this.lists = lists;
116+
}
117+
118+
public Set<String> getSets() {
119+
return sets;
120+
}
121+
122+
public void setSets(Set<String> sets) {
123+
this.sets = sets;
124+
}
125+
126+
public Map<String, Object> getMaps() {
127+
return maps;
128+
}
129+
130+
public void setMaps(Map<String, Object> maps) {
131+
this.maps = maps;
132+
}
133+
134+
// public Properties getProperties() {
135+
// return properties;
136+
// }
137+
//
138+
// public void setProperties(Properties properties) {
139+
// this.properties = properties;
140+
// }
141+
142+
143+
@Override
144+
public String toString() {
145+
return "Person{" +
146+
"id=" + id +
147+
", name='" + name + '\'' +
148+
", age=" + age +
149+
", gender='" + gender + '\'' +
150+
", hobbies=" + Arrays.toString(hobbies) +
151+
", address=" + address +
152+
", lists=" + lists +
153+
", sets=" + sets +
154+
", maps=" + maps +
155+
'}';
156+
}
157+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.mashibing.factory;
2+
3+
import com.mashibing.bean.Person;
4+
import org.springframework.beans.factory.FactoryBean;
5+
6+
/**
7+
* 此方式是spring创建bean方式的一种补充,用户可以按照需求创建对象,
8+
* 创建的对象交由spring IOC容器来进行管理,无论是否是单例,都是在
9+
* 用到的时候才会创建该对象,不用该对象不会创建
10+
*/
11+
public class MyFactoryBean implements FactoryBean<Person> {
12+
/*
13+
* 返回获取的bean
14+
* */
15+
public Person getObject() throws Exception {
16+
Person person = new Person();
17+
person.setId(3);
18+
person.setName("王五");
19+
return person;
20+
}
21+
22+
//获取返回bean的类型
23+
public Class<?> getObjectType() {
24+
return Person.class;
25+
}
26+
27+
//判断当前bean是否是单例的
28+
public boolean isSingleton() {
29+
return true;
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.mashibing.factory;
2+
3+
import com.mashibing.bean.Person;
4+
5+
/**
6+
* 实例工厂
7+
*/
8+
public class PersonInstanceFactory {
9+
10+
public Person getInstance(String name){
11+
Person person = new Person();
12+
person.setId(2);
13+
person.setName(name);
14+
person.setAge(22);
15+
return person;
16+
}
17+
}

0 commit comments

Comments
 (0)