Quellcode durchsuchen

adding controller methods

Trinh Tong vor 7 Jahren
Ursprung
Commit
6d0dfdf04c

+ 9
- 0
src/main/java/io/zipcoder/persistenceapp/controller/PersonController.java Datei anzeigen

@@ -5,6 +5,8 @@ import io.zipcoder.persistenceapp.service.PersonService;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8
+
9
+import org.springframework.web.bind.annotation.PathVariable;
8 10
 import org.springframework.web.bind.annotation.RequestMapping;
9 11
 import org.springframework.web.bind.annotation.RequestMethod;
10 12
 import org.springframework.web.bind.annotation.RestController;
@@ -19,4 +21,11 @@ public class PersonController {
19 21
         Iterable<Person> people = personService.getAllPeople();
20 22
         return new ResponseEntity<>(people, HttpStatus.OK);
21 23
     }
24
+
25
+    @RequestMapping(value = "/person/{id}", method = RequestMethod.GET)
26
+    public ResponseEntity<Person> getPersonById(@PathVariable Integer id) {
27
+        Person p = personService.findPersonById(id);
28
+        return new ResponseEntity<>(p, HttpStatus.OK);
29
+    }
30
+
22 31
 }

+ 0
- 2
src/main/java/io/zipcoder/persistenceapp/service/PersonService.java Datei anzeigen

@@ -10,8 +10,6 @@ import org.springframework.stereotype.Service;
10 10
 import java.sql.JDBCType;
11 11
 import java.sql.ResultSet;
12 12
 import java.sql.SQLException;
13
-import java.util.Arrays;
14
-import java.util.Iterator;
15 13
 import java.util.List;
16 14
 
17 15
 /*