父节点
当前提交
50fb632548

+ 7
- 7
pom.xml 查看文件

25
 	</properties>
25
 	</properties>
26
 
26
 
27
 	<dependencies>
27
 	<dependencies>
28
-		<dependency>
29
-			<groupId>org.hsqldb</groupId>
30
-			<artifactId>hsqldb</artifactId>
31
-			<scope>runtime</scope>
32
-		</dependency>
33
 
28
 
34
 		<dependency>
29
 		<dependency>
35
 			<groupId>org.springframework.boot</groupId>
30
 			<groupId>org.springframework.boot</groupId>
59
         <dependency>
54
         <dependency>
60
             <groupId>org.springframework.boot</groupId>
55
             <groupId>org.springframework.boot</groupId>
61
             <artifactId>spring-boot-starter-data-jpa</artifactId>
56
             <artifactId>spring-boot-starter-data-jpa</artifactId>
62
-            <version>RELEASE</version>
63
-            <scope>compile</scope>
64
         </dependency>
57
         </dependency>
58
+
59
+		<dependency>
60
+			<groupId>org.hsqldb</groupId>
61
+			<artifactId>hsqldb</artifactId>
62
+			<scope>runtime</scope>
63
+		</dependency>
64
+
65
     </dependencies>
65
     </dependencies>
66
 
66
 
67
 	<build>
67
 	<build>

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

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.beans.factory.annotation.Autowired;
6
-import org.springframework.context.annotation.Bean;
7
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
8
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
9
-import org.springframework.orm.jpa.JpaVendorAdapter;
10
-import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
11
-import org.springframework.stereotype.Controller;
12
-import org.springframework.web.bind.annotation.DeleteMapping;
13
-import org.springframework.web.bind.annotation.GetMapping;
14
-import org.springframework.web.bind.annotation.PostMapping;
15
-import org.springframework.web.bind.annotation.PutMapping;
16
-
17
-import javax.activation.DataSource;
18
-import javax.persistence.EntityManagerFactory;
19
-
20
-@Controller
8
+import org.springframework.web.bind.annotation.*;
9
+
10
+
11
+@RestController
21
 public class BakerController {
12
 public class BakerController {
22
 
13
 
23
     @Autowired
14
     @Autowired
24
     private BakerRepository bakerRepository;
15
     private BakerRepository bakerRepository;
25
 
16
 
26
 
17
 
27
-    @GetMapping(path = "/baker")
18
+    @GetMapping("/baker")
28
     public ResponseEntity<Iterable<Baker>> index() {
19
     public ResponseEntity<Iterable<Baker>> index() {
29
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
30
     }
21
     }
31
 
22
 
32
-    @GetMapping(path = "/baker/{id}")
33
-    public ResponseEntity<Baker> show(Long id) {
23
+    @GetMapping("/baker/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
34
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
25
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
35
     }
26
     }
36
 
27
 
37
-    @PostMapping(path = "/baker")
38
-    public ResponseEntity<Baker> create(Baker baker) {
28
+    @PostMapping("/baker")
29
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
39
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
40
     }
31
     }
41
 
32
 
42
-    @PutMapping(path = "/baker")
43
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping("/baker/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
44
         Baker foundBaker = bakerRepository.findOne(id);
35
         Baker foundBaker = bakerRepository.findOne(id);
45
 
36
 
46
         foundBaker.setName(baker.getName());
37
         foundBaker.setName(baker.getName());
49
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
50
     }
41
     }
51
 
42
 
52
-    @DeleteMapping(path = "/baker")
53
-    public ResponseEntity<Boolean> destroy(Long id) {
43
+    @DeleteMapping("/baker/{id}")
44
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
54
         this.bakerRepository.delete(id);
45
         this.bakerRepository.delete(id);
55
         return new ResponseEntity<>(true, HttpStatus.OK);
46
         return new ResponseEntity<>(true, HttpStatus.OK);
56
     }
47
     }

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

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

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

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
-import org.springframework.data.annotation.Id;
4
 
3
 
5
 import javax.persistence.*;
4
 import javax.persistence.*;
6
 
5
 

+ 0
- 1
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 org.springframework.data.annotation.Id;
4
 
3
 
5
 import javax.persistence.*;
4
 import javax.persistence.*;
6
 
5
 

+ 1
- 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;
5
 import org.springframework.stereotype.Repository;
6
 import org.springframework.stereotype.Repository;
6
 
7
 
7
 @Repository
8
 @Repository

+ 1
- 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;
5
 import org.springframework.stereotype.Repository;
6
 import org.springframework.stereotype.Repository;
6
 
7
 
7
 @Repository
8
 @Repository