Lauren Green 6 anni fa
parent
commit
31ae858e28

+ 1
- 1
pom.xml Vedi File

@@ -14,7 +14,7 @@
14 14
 	<parent>
15 15
 		<groupId>org.springframework.boot</groupId>
16 16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>1.5.2.RELEASE</version>
17
+		<version>1.5.3.RELEASE</version>
18 18
 		<relativePath/> <!-- lookup parent from repository -->
19 19
 	</parent>
20 20
 

+ 20
- 0
src/main/java/io/zipcoder/crudapp/Person.java Vedi File

@@ -0,0 +1,20 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.GenerationType;
6
+import javax.persistence.Id;
7
+
8
+@Entity
9
+public class Person {
10
+
11
+    @Id
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
13
+    private int id;
14
+    private String firstName;
15
+    private String lastName;
16
+
17
+    public Person() {
18
+
19
+    }
20
+}

+ 39
- 0
src/main/java/io/zipcoder/crudapp/PersonController.java Vedi File

@@ -0,0 +1,39 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.web.bind.annotation.*;
5
+
6
+import java.util.ArrayList;
7
+import java.util.List;
8
+
9
+@RestController
10
+public class PersonController {
11
+
12
+    @Autowired
13
+    PersonRepository personRepository;
14
+
15
+    @RequestMapping(value = "/people", method = RequestMethod.POST)
16
+    public Person createPerson(@RequestBody Person p) {
17
+        return personRepository.save(p);
18
+    }
19
+
20
+    @RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
21
+    public Person getPerson(@PathVariable int id) {
22
+        return personRepository.findOne(id);
23
+    }
24
+
25
+    @RequestMapping(value = "/people", method = RequestMethod.GET)
26
+    public List<Person> getPersonList() {
27
+        return personRepository.findAll();
28
+    }
29
+
30
+    @RequestMapping(value = "/people/{id}", method = RequestMethod.PUT)
31
+    public Person updatePerson(@RequestBody Person p) {
32
+        return personRepository.save(p);
33
+    }
34
+
35
+    @RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)
36
+    public void deletePerson(@PathVariable int id) {
37
+        personRepository.delete(id);
38
+    }
39
+}

+ 6
- 0
src/main/java/io/zipcoder/crudapp/PersonRepository.java Vedi File

@@ -0,0 +1,6 @@
1
+package io.zipcoder.crudapp;
2
+
3
+import org.springframework.data.repository.CrudRepository;
4
+
5
+public interface PersonRepository extends CrudRepository<Person, Integer> {
6
+}