소스 검색

Person

Learner
Student
Teacher
Instructor
People
Students
Instructors
Classroom
StudentConfig - noParam Constructors Used
 - Added toString to People to run SpringBootApp
InstructorsConfig
Nick Satinover 6 년 전
부모
커밋
bf2d1d19b0

+ 8
- 0
demo/pom.xml 파일 보기

@@ -40,6 +40,14 @@
40 40
 			<artifactId>spring-boot-starter-test</artifactId>
41 41
 			<scope>test</scope>
42 42
 		</dependency>
43
+
44
+		<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
45
+		<dependency>
46
+			<groupId>org.springframework</groupId>
47
+			<artifactId>spring-beans</artifactId>
48
+			<version>5.1.2.RELEASE</version>
49
+		</dependency>
50
+
43 51
 	</dependencies>
44 52
 
45 53
 	<build>

+ 4
- 2
demo/src/main/java/com/example/demo/DemoApplication.java 파일 보기

@@ -14,8 +14,10 @@ public class DemoApplication {
14 14
 		ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
15 15
 		// SpringApplication.run(DemoApplication.class, args);
16 16
 
17
-        Students students = new Students();
18
-        System.out.println(students.toString());
17
+//        Students students = new Students();
18
+//        System.out.println(students.toString());
19
+
20
+
19 21
 
20 22
 	}
21 23
 }

+ 51
- 0
demo/src/main/java/com/example/demo/InstructorsConfig.java 파일 보기

@@ -0,0 +1,51 @@
1
+package com.example.demo;
2
+
3
+import org.springframework.beans.factory.annotation.Qualifier;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.context.annotation.Configuration;
6
+import org.springframework.context.annotation.Primary;
7
+import org.springframework.stereotype.Component;
8
+import java.util.ArrayList;
9
+
10
+@Configuration
11
+public class InstructorsConfig {
12
+
13
+    @Bean(name = "tcUsaInstructors")
14
+    public Instructors tcUsaInstructors(){
15
+        ArrayList<Instructor> tcUsaInstructors = new ArrayList<>();
16
+
17
+        tcUsaInstructors.add(new Instructor(1, "Kris"));
18
+        tcUsaInstructors.add(new Instructor(2, "Leon"));
19
+        tcUsaInstructors.add(new Instructor(3, "Dolio"));
20
+        tcUsaInstructors.add(new Instructor(4, "Wilhem"));
21
+
22
+        return new Instructors(tcUsaInstructors);
23
+    }
24
+
25
+    @Bean(name = "tcUkInstructors")
26
+    public Instructors tcUkInstructors(){
27
+        ArrayList<Instructor> tcUkInstructors = new ArrayList<>();
28
+
29
+        tcUkInstructors.add(new Instructor(1, "Old Kris"));
30
+        tcUkInstructors.add(new Instructor(2, "Old Leon"));
31
+        tcUkInstructors.add(new Instructor(3, "Old Dolio"));
32
+        tcUkInstructors.add(new Instructor(4, "Old Wilhem"));
33
+
34
+        return new Instructors(tcUkInstructors);
35
+    }
36
+
37
+    @Bean(name = "instructors")
38
+    @Primary
39
+    public Instructors instructors(){
40
+        Instructors allInstructors = new Instructors();
41
+
42
+        allInstructors.addAll(tcUsaInstructors());
43
+        allInstructors.addAll(tcUkInstructors());
44
+
45
+        return allInstructors;
46
+    }
47
+
48
+
49
+}
50
+
51
+

+ 21
- 1
demo/src/main/java/com/example/demo/People.java 파일 보기

@@ -4,7 +4,7 @@ import java.util.ArrayList;
4 4
 import java.util.List;
5 5
 
6 6
 public abstract class People<PersonType extends Person> implements Iterable<PersonType> {
7
-    List<PersonType> personList;
7
+    List<PersonType> personList = new ArrayList<>();
8 8
 
9 9
     People(){
10 10
 
@@ -49,4 +49,24 @@ public abstract class People<PersonType extends Person> implements Iterable<Pers
49 49
     public List<PersonType> findAll(){
50 50
         return personList;
51 51
     }
52
+
53
+    @Override
54
+    public String toString() {
55
+        int i = 1;
56
+        StringBuilder builder = new StringBuilder
57
+                ("--- List of " +
58
+                this.getClass()
59
+                .getName()
60
+                .replaceAll("com.example.demo.", "") + " ---\n");
61
+
62
+        for (PersonType p: personList) {
63
+            builder.append(
64
+                    "Record " + i           +
65
+                    " Name: " + p.getName() +
66
+                    " ID: "   + p.getId()   +
67
+                    "\n");
68
+            i++;
69
+        }
70
+        return builder.toString().trim();
71
+    }
52 72
 }

+ 39
- 3
demo/src/main/java/com/example/demo/StudentConfig.java 파일 보기

@@ -1,19 +1,55 @@
1 1
 package com.example.demo;
2 2
 
3 3
 import com.sun.tools.javac.util.List;
4
+import org.springframework.beans.factory.annotation.Qualifier;
4 5
 import org.springframework.context.annotation.Bean;
5 6
 import org.springframework.context.annotation.Configuration;
7
+import org.springframework.stereotype.Component;
8
+
9
+import java.util.ArrayList;
6 10
 
7 11
 @Configuration
8 12
 public class StudentConfig {
9 13
 
10 14
     @Bean(name = "students")
15
+    //@Qualifier("currentStudents")
11 16
     public Students currentStudents(){
12
-        return new Students();
17
+        ArrayList<Student> currentStudents = new ArrayList<>();
18
+        
19
+        currentStudents.add(new Student(1, "Ned Redmond"));
20
+        currentStudents.add(new Student(2, "Seth Abrams"));
21
+        currentStudents.add(new Student(3, "Akeem Cherry"));
22
+        currentStudents.add(new Student(4, "Whitney Martinez"));
23
+        currentStudents.add(new Student(5, "Nira Parikh"));
24
+        currentStudents.add(new Student(6, "Connor Dunnigan"));
25
+        currentStudents.add(new Student(7, "Christian Sheridan"));
26
+        currentStudents.add(new Student(8, "Curtis Cook"));
27
+        currentStudents.add(new Student(9, "Nuridalia Hernandez"));
28
+        currentStudents.add(new Student(10, "Brandon DeFrancis"));
29
+
30
+        return new Students(currentStudents);
13 31
     }
14 32
 
15
-    @Bean
33
+    @Bean(name = "previousStudents")
34
+    //@Qualifier("previousStudents")
16 35
     public Students previousStudents(){
17
-        return new Students();
36
+        ArrayList<Student> previousStudents = new ArrayList<>();
37
+
38
+        previousStudents.add(new Student(1, "OldNed Redmond"));
39
+        previousStudents.add(new Student(2, "OldSeth Abrams"));
40
+        previousStudents.add(new Student(3, "OldAkeem Cherry"));
41
+        previousStudents.add(new Student(4, "OldWhitney Martinez"));
42
+        previousStudents.add(new Student(5, "OldNira Parikh"));
43
+        previousStudents.add(new Student(6, "OldConnor Dunnigan"));
44
+        previousStudents.add(new Student(7, "OldChristian Sheridan"));
45
+        previousStudents.add(new Student(8, "OldCurtis Cook"));
46
+        previousStudents.add(new Student(9, "OldNuridalia Hernandez"));
47
+        previousStudents.add(new Student(10, "OldBrandon DeFrancis"));
48
+
49
+        return new Students(previousStudents);
50
+
18 51
     }
52
+
53
+
19 54
 }
55
+

+ 2
- 0
demo/src/main/java/com/example/demo/Students.java 파일 보기

@@ -29,4 +29,6 @@ public class Students extends People<Student> {
29 29
     public Spliterator spliterator() {
30 30
         return null;
31 31
     }
32
+
33
+
32 34
 }