瀏覽代碼

Completed

Brandon Defrancis 5 年之前
父節點
當前提交
0ba8182d3e

二進制
.DS_Store 查看文件


+ 12
- 2
pom.xml 查看文件

@@ -11,10 +11,11 @@
11 11
 	<name>bakery</name>
12 12
 	<description>Demo project for Spring Boot</description>
13 13
 
14
+
14 15
 	<parent>
15 16
 		<groupId>org.springframework.boot</groupId>
16 17
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
18
+		<version>1.5.11.RELEASE</version>
18 19
 		<relativePath/> <!-- lookup parent from repository -->
19 20
 	</parent>
20 21
 
@@ -29,6 +30,11 @@
29 30
 			<groupId>org.springframework.boot</groupId>
30 31
 			<artifactId>spring-boot-starter</artifactId>
31 32
 		</dependency>
33
+		<dependency>
34
+			<groupId>org.hsqldb</groupId>
35
+			<artifactId>hsqldb</artifactId>
36
+			<scope>runtime</scope>
37
+		</dependency>
32 38
 
33 39
 		<dependency>
34 40
 			<groupId>org.springframework.boot</groupId>
@@ -50,7 +56,11 @@
50 56
 			<artifactId>spring-data-commons</artifactId>
51 57
 			<version>1.13.10.RELEASE</version>
52 58
 		</dependency>
53
-	</dependencies>
59
+        <dependency>
60
+            <groupId>org.springframework.boot</groupId>
61
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
62
+        </dependency>
63
+    </dependencies>
54 64
 
55 65
 	<build>
56 66
 		<plugins>

二進制
src/.DS_Store 查看文件


二進制
src/main/.DS_Store 查看文件


二進制
src/main/java/.DS_Store 查看文件


二進制
src/main/java/com/.DS_Store 查看文件


二進制
src/main/java/com/zipcodewilmington/.DS_Store 查看文件


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

@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 
6 6
 @SpringBootApplication
7 7
 public class BakeryApplication {
8
-
9 8
 	public static void main(String[] args) {
10 9
 		SpringApplication.run(BakeryApplication.class, args);
11 10
 	}

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

@@ -2,35 +2,49 @@ 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.PathVariable;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
7 12
 
13
+@RestController
8 14
 public class BakerController {
9 15
 
10
-    private BakerRepository bakerRepository;
16
+    private final BakerRepository bakerRepository;
11 17
 
18
+    @Autowired
19
+    public BakerController(BakerRepository bakerRepository) {
20
+        this.bakerRepository = bakerRepository;
21
+    }
22
+
23
+    @RequestMapping(value="/bakers", method= RequestMethod.GET)
12 24
     public ResponseEntity<Iterable<Baker>> index() {
13 25
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 26
     }
15 27
 
16
-    public ResponseEntity<Baker> show(Long id) {
28
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.GET)
29
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17 30
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 31
     }
19 32
 
33
+    @RequestMapping(value="/bakers", method= RequestMethod.POST)
20 34
     public ResponseEntity<Baker> create(Baker baker) {
21 35
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 36
     }
23 37
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
38
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.PUT)
39
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
25 40
         Baker foundBaker = bakerRepository.findOne(id);
26
-
27 41
         foundBaker.setName(baker.getName());
28 42
         foundBaker.setSpecialty(baker.getSpecialty());
29
-
30 43
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 44
     }
32 45
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
46
+    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.DELETE)
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34 48
         this.bakerRepository.delete(id);
35 49
         return new ResponseEntity<>(true, HttpStatus.OK);
36 50
     }

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

@@ -2,33 +2,49 @@ 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.web.bind.annotation.PathVariable;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
7 12
 
13
+@RestController
8 14
 public class MuffinController {
9 15
 
10
-    private MuffinRepository muffinRepository;
16
+    private final MuffinRepository muffinRepository;
11 17
 
18
+    @Autowired
19
+    public MuffinController(MuffinRepository muffinRepository) {
20
+        this.muffinRepository = muffinRepository;
21
+    }
22
+
23
+    @RequestMapping(value="/muffins", method= RequestMethod.GET)
12 24
     public ResponseEntity<Iterable<Muffin>> index() {
13 25
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 26
     }
15 27
 
16
-    public ResponseEntity<Muffin> show(Long id) {
28
+    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.GET)
29
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 30
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 31
     }
19 32
 
33
+    @RequestMapping(value="/muffins", method= RequestMethod.POST)
20 34
     public ResponseEntity<Muffin> create(Muffin muffin) {
21 35
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 36
     }
23 37
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
38
+    @RequestMapping(value="/muffin/{MUFFIN_ID}", method=RequestMethod.PUT)
39
+    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
25 40
         Muffin foundMuffin = muffinRepository.findOne(id);
26 41
         foundMuffin.setFlavor(muffin.getFlavor());
27 42
 
28 43
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 44
     }
30 45
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
46
+    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.DELETE)
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 48
         this.muffinRepository.delete(id);
33 49
         return new ResponseEntity<>(true, HttpStatus.OK);
34 50
     }

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

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

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

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

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

@@ -2,6 +2,8 @@ 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.stereotype.Repository;
5 6
 
7
+@Repository
6 8
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7 9
 }

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

@@ -2,6 +2,8 @@ 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.stereotype.Repository;
5 6
 
7
+@Repository
6 8
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7 9
 }