Browse Source

requeastmapping

Seth 5 years ago
parent
commit
dcbdd67a70
1 changed files with 11 additions and 9 deletions
  1. 11
    9
      src/main/java/io/zipcoder/crudapp/PersonController.java

+ 11
- 9
src/main/java/io/zipcoder/crudapp/PersonController.java View File

@@ -1,15 +1,11 @@
1 1
 package io.zipcoder.crudapp;
2 2
 
3
-import org.springframework.web.bind.annotation.PathVariable;
4
-import org.springframework.web.bind.annotation.RequestBody;
5
-import org.springframework.web.bind.annotation.RequestMapping;
6
-import org.springframework.web.bind.annotation.RestController;
3
+import org.springframework.web.bind.annotation.*;
7 4
 
8 5
 import java.util.ArrayList;
9 6
 import java.util.List;
10 7
 
11
-import static org.springframework.web.bind.annotation.RequestMethod.GET;
12
-import static org.springframework.web.bind.annotation.RequestMethod.POST;
8
+import static org.springframework.web.bind.annotation.RequestMethod.*;
13 9
 
14 10
 @RestController
15 11
 public class PersonController {
@@ -20,8 +16,7 @@ public class PersonController {
20 16
     }
21 17
 
22 18
     @RequestMapping(value = "/people", method = POST)
23
-    @RequestBody
24
-    public Person createPerson(Person p){
19
+    public Person createPerson(@RequestBody Person p){
25 20
         return new Person();
26 21
     }
27 22
 
@@ -35,11 +30,18 @@ public class PersonController {
35 30
         return null;
36 31
     }
37 32
 
33
+    @RequestMapping(value = "/people", method = GET)
38 34
     public List<Person> getPersonList(){
39 35
         return this.personList;
40 36
     }
41 37
 
42
-    public Person updatePerson(Person p){
38
+    @RequestMapping(value = "/people", method = PUT)
39
+    public Person updatePerson(@RequestBody Person p){
43 40
         return new Person();
44 41
     }
42
+
43
+    @RequestMapping(value = "/people/{id}", method = DELETE)
44
+    public void deletePerson(@PathVariable int id) {
45
+        personList.remove(id);
46
+    }
45 47
 }