浏览代码

fixed path variables

Lauren Green 5 年前
父节点
当前提交
44bf8993e9

+ 3
- 3
src/main/java/com/example/demo/Controllers/BakerController.java 查看文件

@@ -22,7 +22,7 @@ public class BakerController {
22 22
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
23 23
     }
24 24
 
25
-    @RequestMapping(value="/bakers/id", method= RequestMethod.GET)
25
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.GET)
26 26
     public ResponseEntity<Baker> show(@PathVariable Long id) {
27 27
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
28 28
     }
@@ -32,7 +32,7 @@ public class BakerController {
32 32
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
33 33
     }
34 34
 
35
-    @RequestMapping(value="/bakers/id", method= RequestMethod.PUT)
35
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.PUT)
36 36
     public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
37 37
         Baker foundBaker = bakerRepository.findById(id).get();
38 38
 
@@ -42,7 +42,7 @@ public class BakerController {
42 42
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
43 43
     }
44 44
 
45
-    @RequestMapping(value="/bakers/id", method= RequestMethod.DELETE)
45
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.DELETE)
46 46
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
47 47
         this.bakerRepository.deleteById(id);
48 48
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 3
- 3
src/main/java/com/example/demo/Controllers/MuffinController.java 查看文件

@@ -22,7 +22,7 @@ public class MuffinController {
22 22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
23 23
     }
24 24
 
25
-    @RequestMapping(value="/muffins/id", method= RequestMethod.GET)
25
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.GET)
26 26
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
27 27
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
28 28
     }
@@ -32,7 +32,7 @@ public class MuffinController {
32 32
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
33 33
     }
34 34
 
35
-    @RequestMapping(value="/muffins/id", method= RequestMethod.PUT)
35
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.PUT)
36 36
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
37 37
         Muffin foundMuffin = muffinRepository.findById(id).get();
38 38
         foundMuffin.setFlavor(muffin.getFlavor());
@@ -40,7 +40,7 @@ public class MuffinController {
40 40
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
41 41
     }
42 42
 
43
-    @RequestMapping(value="/muffins/id", method= RequestMethod.DELETE)
43
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.DELETE)
44 44
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
45 45
         this.muffinRepository.deleteById(id);
46 46
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 1
- 0
src/test/java/com/example/demo/BakeryApplicationTests.java 查看文件

@@ -26,4 +26,5 @@ public class BakeryApplicationTests {
26 26
         Assert.assertNotNull(muffinController);
27 27
     }
28 28
 
29
+
29 30
 }