Nick Satinover 6 lat temu
rodzic
commit
67736d0adc

+ 6
- 6
pom.xml Wyświetl plik

@@ -11,12 +11,12 @@
11 11
 	<name>bakery</name>
12 12
 	<description>Demo project for Spring Boot</description>
13 13
 
14
-	<parent>
15
-		<groupId>org.springframework.boot</groupId>
16
-		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
18
-		<relativePath/> <!-- lookup parent from repository -->
19
-	</parent>
14
+    <parent>
15
+        <groupId>org.springframework.boot</groupId>
16
+        <artifactId>spring-boot-starter-parent</artifactId>
17
+        <version>1.5.11.RELEASE</version>
18
+        <relativePath/> <!-- lookup parent from repository -->
19
+    </parent>
20 20
 
21 21
 	<properties>
22 22
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java Wyświetl plik

@@ -2,11 +2,22 @@ package com.zipcodewilmington.bakery;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.boot.autoconfigure.domain.EntityScan;
6
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
7
+import org.springframework.context.annotation.Bean;
5 8
 
9
+@EntityScan
6 10
 @SpringBootApplication
7 11
 public class BakeryApplication {
8 12
 
9 13
 	public static void main(String[] args) {
10 14
 		SpringApplication.run(BakeryApplication.class, args);
11 15
 	}
16
+
17
+//	@Bean
18
+//	ServletRegistrationBean h2servletRegistration(){
19
+//		ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
20
+//		registrationBean.addUrlMappings("/console/*");
21
+//		return registrationBean;
22
+//	}
12 23
 }

+ 12
- 1
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Wyświetl plik

@@ -2,25 +2,35 @@ 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;
6
+import org.springframework.beans.factory.annotation.Qualifier;
5 7
 import org.springframework.http.HttpStatus;
6 8
 import org.springframework.http.ResponseEntity;
9
+import org.springframework.web.bind.annotation.*;
7 10
 
11
+@RestController
8 12
 public class BakerController {
9 13
 
14
+    @Autowired
15
+//    @Qualifier("beanBaker")
10 16
     private BakerRepository bakerRepository;
11 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
 
23
+    @GetMapping("/baker/{id}")
16 24
     public ResponseEntity<Baker> show(Long id) {
17 25
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 26
     }
19 27
 
28
+    @PostMapping("/baker")
20 29
     public ResponseEntity<Baker> create(Baker baker) {
21 30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 31
     }
23 32
 
33
+    @RequestMapping(value = "/baker/{id}", method = RequestMethod.PUT)
24 34
     public ResponseEntity<Baker> update(Long id, Baker baker) {
25 35
         Baker foundBaker = bakerRepository.findOne(id);
26 36
 
@@ -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
     }

+ 10
- 1
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Wyświetl plik

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Wyświetl plik

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Wyświetl plik

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

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Wyświetl plik

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

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Wyświetl plik

@@ -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
 }

+ 4
- 0
src/main/resources/application-h2.properties Wyświetl plik

@@ -0,0 +1,4 @@
1
+spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle
2
+spring.datasource.platform=h2
3
+spring.jpa.hibernate.ddl-auto=none
4
+spring.datasource.continue-on-error=true

+ 2
- 0
src/main/resources/application.properties Wyświetl plik

@@ -0,0 +1,2 @@
1
+spring.profiles.active=h2
2
+spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect