William Brown 5 年前
父节点
当前提交
3b74d088d5

二进制
.DS_Store 查看文件


+ 14
- 3
pom.xml 查看文件

14
 	<parent>
14
 	<parent>
15
 		<groupId>org.springframework.boot</groupId>
15
 		<groupId>org.springframework.boot</groupId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
17
+		<version>1.5.11.RELEASE</version>
18
 		<relativePath/> <!-- lookup parent from repository -->
18
 		<relativePath/> <!-- lookup parent from repository -->
19
 	</parent>
19
 	</parent>
20
 
20
 
50
 			<artifactId>spring-data-commons</artifactId>
50
 			<artifactId>spring-data-commons</artifactId>
51
 			<version>1.13.10.RELEASE</version>
51
 			<version>1.13.10.RELEASE</version>
52
 		</dependency>
52
 		</dependency>
53
-	</dependencies>
53
+        <dependency>
54
+            <groupId>org.hsqldb</groupId>
55
+            <artifactId>hsqldb</artifactId>
56
+            <scope>runtime</scope>
57
+        </dependency>
58
+        <dependency>
59
+            <groupId>org.springframework.boot</groupId>
60
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
61
+            <version>RELEASE</version>
62
+            <scope>compile</scope>
63
+        </dependency>
64
+    </dependencies>
54
 
65
 
55
 	<build>
66
 	<build>
56
 		<plugins>
67
 		<plugins>
62
 	</build>
73
 	</build>
63
 
74
 
64
 
75
 
65
-</project>
76
+</project>

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

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.ResponseEntity;
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
 public class BakerController {
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
     public ResponseEntity<Iterable<Baker>> index() {
24
     public ResponseEntity<Iterable<Baker>> index() {
13
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
25
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14
     }
26
     }
15
 
27
 
16
-    public ResponseEntity<Baker> show(Long id) {
28
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.GET)
29
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
30
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18
     }
31
     }
19
 
32
 
33
+    @RequestMapping(value = "/bakers", method = RequestMethod.POST)
20
     public ResponseEntity<Baker> create(Baker baker) {
34
     public ResponseEntity<Baker> create(Baker baker) {
21
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
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/{id}", method = RequestMethod.PUT)
39
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
25
         Baker foundBaker = bakerRepository.findOne(id);
40
         Baker foundBaker = bakerRepository.findOne(id);
26
 
41
 
27
         foundBaker.setName(baker.getName());
42
         foundBaker.setName(baker.getName());
30
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
45
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31
     }
46
     }
32
 
47
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
48
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.DELETE)
49
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34
         this.bakerRepository.delete(id);
50
         this.bakerRepository.delete(id);
35
         return new ResponseEntity<>(true, HttpStatus.OK);
51
         return new ResponseEntity<>(true, HttpStatus.OK);
36
     }
52
     }

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

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

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

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Baker {
9
 public class Baker {
10
+
11
+    @Id
12
+    @GeneratedValue
4
     private Long id;
13
     private Long id;
5
 
14
 
6
     private String name;
15
     private String name;

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

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.Id;
6
+
7
+@Entity
3
 public class Muffin {
8
 public class Muffin {
4
 
9
 
10
+    @Id
11
+    @GeneratedValue
5
     private Long id;
12
     private Long id;
6
 
13
 
7
     private String flavor;
14
     private String flavor;

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

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import org.springframework.data.repository.CrudRepository;
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
9
+@RepositoryRestResource(collectionResourceRel = "bakers", path = "bakers")
6
 public interface BakerRepository extends CrudRepository<Baker, Long> {
10
 public interface BakerRepository extends CrudRepository<Baker, Long> {
11
+
7
 }
12
 }

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

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Muffin;
3
 import com.zipcodewilmington.bakery.Models.Muffin;
4
 import org.springframework.data.repository.CrudRepository;
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
9
+@RepositoryRestResource(collectionResourceRel = "bakers", path = "bakers")
6
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
10
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
11
+
7
 }
12
 }