浏览代码

{only finished part1}

Jacqueline Joson 5 年前
父节点
当前提交
4367964f9e

+ 79
- 0
src/main/java/io/zipcoder/persistenceapp/Person.java 查看文件

@@ -0,0 +1,79 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+import java.util.Date;
4
+
5
+public class Person {
6
+    private String firstName;
7
+    private String lastName;
8
+    private int id;
9
+    private Date birthdate;
10
+    private String mobile;
11
+
12
+    public Person() {
13
+    }
14
+
15
+    public Person(String firstName, String lastName, int id, Date birthdate, String mobile) {
16
+        this.firstName = firstName;
17
+        this.lastName = lastName;
18
+        this.id = id;
19
+        this.birthdate = birthdate;
20
+        this.mobile = mobile;
21
+    }
22
+
23
+    public Person(String firstName, String lastName, Date birthdate) {
24
+        this.firstName = firstName;
25
+        this.lastName = lastName;
26
+        this.birthdate = birthdate;
27
+    }
28
+
29
+    public String getFirstName() {
30
+        return firstName;
31
+    }
32
+
33
+    public void setFirstName(String firstName) {
34
+        this.firstName = firstName;
35
+    }
36
+
37
+    public String getLastName() {
38
+        return lastName;
39
+    }
40
+
41
+    public void setLastName(String lastName) {
42
+        this.lastName = lastName;
43
+    }
44
+
45
+    public int getId() {
46
+        return id;
47
+    }
48
+
49
+    public void setId(int id) {
50
+        this.id = id;
51
+    }
52
+
53
+    public Date getBirthdate() {
54
+        return birthdate;
55
+    }
56
+
57
+    public void setBirthdate(Date birthdate) {
58
+        this.birthdate = birthdate;
59
+    }
60
+
61
+    public String getMobile() {
62
+        return mobile;
63
+    }
64
+
65
+    public void setMobile(String mobile) {
66
+        this.mobile = mobile;
67
+    }
68
+
69
+    @Override
70
+    public String toString() {
71
+        return "Person{" +
72
+                "firstName='" + firstName + '\'' +
73
+                ", lastName='" + lastName + '\'' +
74
+                ", id=" + id +
75
+                ", birthdate=" + birthdate +
76
+                ", mobile='" + mobile + '\'' +
77
+                '}';
78
+    }
79
+}

+ 20
- 0
src/main/java/io/zipcoder/persistenceapp/PersonController.java 查看文件

@@ -0,0 +1,20 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.http.HttpStatus;
5
+import org.springframework.http.ResponseEntity;
6
+import org.springframework.web.bind.annotation.PostMapping;
7
+import org.springframework.web.bind.annotation.RestController;
8
+
9
+@RestController
10
+public class PersonController {
11
+
12
+    @Autowired
13
+    PersonRepository personRepository;
14
+
15
+    @PostMapping("/create")
16
+    public ResponseEntity<Person> create (Person person) {
17
+        return new ResponseEntity<>(this.personRepository.save(person), HttpStatus.OK);
18
+    }
19
+
20
+}

+ 10
- 0
src/main/java/io/zipcoder/persistenceapp/PersonRepository.java 查看文件

@@ -0,0 +1,10 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+import org.springframework.jdbc.core.JdbcTemplate;
4
+import org.springframework.stereotype.Repository;
5
+
6
+@Repository
7
+public class PersonRepository {
8
+    public void save(Person person) {
9
+    }
10
+}

+ 22
- 0
src/main/java/io/zipcoder/persistenceapp/PersonService.java 查看文件

@@ -0,0 +1,22 @@
1
+package io.zipcoder.persistenceapp;
2
+
3
+
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.jdbc.core.JdbcTemplate;
6
+
7
+public class PersonService  {
8
+
9
+    @Autowired
10
+    JdbcTemplate jdbcTemplate;
11
+
12
+    public void addPerson(Person person) {
13
+        jdbcTemplate.execute("");
14
+    }
15
+
16
+    public void getAll() {
17
+        jdbcTemplate.execute("SELECT * FROM Person");
18
+    }
19
+
20
+
21
+    //look up jbdctemplate methods and execute via SQL queries - execute, query, class row-mapper, etc.
22
+}