2 次程式碼提交

作者 SHA1 備註 提交日期
  Michelle DiMarino 50fb632548 it works 5 年之前
  Michelle DiMarino 060b956985 commit 1 5 年之前

二進制
.DS_Store 查看文件


+ 14
- 2
pom.xml 查看文件

@@ -14,7 +14,7 @@
14 14
 	<parent>
15 15
 		<groupId>org.springframework.boot</groupId>
16 16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
17
+		<version>1.5.11.RELEASE</version>
18 18
 		<relativePath/> <!-- lookup parent from repository -->
19 19
 	</parent>
20 20
 
@@ -25,6 +25,7 @@
25 25
 	</properties>
26 26
 
27 27
 	<dependencies>
28
+
28 29
 		<dependency>
29 30
 			<groupId>org.springframework.boot</groupId>
30 31
 			<artifactId>spring-boot-starter</artifactId>
@@ -50,7 +51,18 @@
50 51
 			<artifactId>spring-data-commons</artifactId>
51 52
 			<version>1.13.10.RELEASE</version>
52 53
 		</dependency>
53
-	</dependencies>
54
+        <dependency>
55
+            <groupId>org.springframework.boot</groupId>
56
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
57
+        </dependency>
58
+
59
+		<dependency>
60
+			<groupId>org.hsqldb</groupId>
61
+			<artifactId>hsqldb</artifactId>
62
+			<scope>runtime</scope>
63
+		</dependency>
64
+
65
+    </dependencies>
54 66
 
55 67
 	<build>
56 68
 		<plugins>

+ 5
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java 查看文件

@@ -3,10 +3,15 @@ package com.zipcodewilmington.bakery;
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 
6
+import javax.persistence.EntityManager;
7
+import javax.persistence.EntityManagerFactory;
8
+import javax.persistence.Persistence;
9
+
6 10
 @SpringBootApplication
7 11
 public class BakeryApplication {
8 12
 
9 13
 	public static void main(String[] args) {
14
+
10 15
 		SpringApplication.run(BakeryApplication.class, args);
11 16
 	}
12 17
 }

+ 15
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java 查看文件

@@ -2,26 +2,36 @@ package com.zipcodewilmington.bakery.Controllers;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.http.HttpStatus;
6 7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
7 9
 
10
+
11
+@RestController
8 12
 public class BakerController {
9 13
 
14
+    @Autowired
10 15
     private BakerRepository bakerRepository;
11 16
 
17
+
18
+    @GetMapping("/baker")
12 19
     public ResponseEntity<Iterable<Baker>> index() {
13 20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 21
     }
15 22
 
16
-    public ResponseEntity<Baker> show(Long id) {
23
+    @GetMapping("/baker/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17 25
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 26
     }
19 27
 
20
-    public ResponseEntity<Baker> create(Baker baker) {
28
+    @PostMapping("/baker")
29
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
21 30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 31
     }
23 32
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping("/baker/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
25 35
         Baker foundBaker = bakerRepository.findOne(id);
26 36
 
27 37
         foundBaker.setName(baker.getName());
@@ -30,7 +40,8 @@ public class BakerController {
30 40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 41
     }
32 42
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
43
+    @DeleteMapping("/baker/{id}")
44
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34 45
         this.bakerRepository.delete(id);
35 46
         return new ResponseEntity<>(true, HttpStatus.OK);
36 47
     }

+ 18
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java 查看文件

@@ -2,33 +2,47 @@ package com.zipcodewilmington.bakery.Controllers;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.http.HttpStatus;
6 7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.*;
7 10
 
11
+import javax.persistence.EntityManager;
12
+import javax.persistence.EntityManagerFactory;
13
+import javax.persistence.Persistence;
14
+
15
+@RestController
8 16
 public class MuffinController {
9 17
 
18
+    @Autowired
10 19
     private MuffinRepository muffinRepository;
11 20
 
21
+    @GetMapping("/muffin")
12 22
     public ResponseEntity<Iterable<Muffin>> index() {
13 23
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 24
     }
15 25
 
16
-    public ResponseEntity<Muffin> show(Long id) {
26
+    @GetMapping("/muffin/{id}")
27
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 28
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 29
     }
19 30
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
31
+    @PostMapping("/muffin")
32
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21 33
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 34
     }
23 35
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
36
+    @PutMapping("/muffin/{id}")
37
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25 38
         Muffin foundMuffin = muffinRepository.findOne(id);
26 39
         foundMuffin.setFlavor(muffin.getFlavor());
27 40
 
28 41
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 42
     }
30 43
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
44
+    @DeleteMapping("/muffin/{id}")
45
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 46
         this.muffinRepository.delete(id);
33 47
         return new ResponseEntity<>(true, HttpStatus.OK);
34 48
     }

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java 查看文件

@@ -1,12 +1,22 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
3 7
 public class Baker {
8
+
9
+    @Id
10
+    @GeneratedValue(strategy = GenerationType.AUTO)
4 11
     private Long id;
5 12
 
13
+    @Column
6 14
     private String name;
7 15
 
16
+    @Column
8 17
     private String employeeId;
9 18
 
19
+    @Column
10 20
     private String specialty;
11 21
 
12 22
     public Baker(String name, String employeeId, String specialty) {

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java 查看文件

@@ -1,11 +1,19 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
3 7
 public class Muffin {
4 8
 
9
+    @Id
10
+    @GeneratedValue(strategy = GenerationType.AUTO)
5 11
     private Long id;
6 12
 
13
+    @Column
7 14
     private String flavor;
8 15
 
16
+
9 17
     public Muffin(String flavor) {
10 18
         this.flavor = flavor;
11 19
     }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java 查看文件

@@ -2,6 +2,9 @@ package com.zipcodewilmington.bakery.Repositories;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5 7
 
8
+@Repository
6 9
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7 10
 }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java 查看文件

@@ -2,6 +2,9 @@ package com.zipcodewilmington.bakery.Repositories;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5 7
 
8
+@Repository
6 9
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7 10
 }