Nick Satinover пре 6 година
родитељ
комит
67736d0adc

+ 6
- 6
pom.xml Прегледај датотеку

11
 	<name>bakery</name>
11
 	<name>bakery</name>
12
 	<description>Demo project for Spring Boot</description>
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
 	<properties>
21
 	<properties>
22
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java Прегледај датотеку

2
 
2
 
3
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
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
 @SpringBootApplication
10
 @SpringBootApplication
7
 public class BakeryApplication {
11
 public class BakeryApplication {
8
 
12
 
9
 	public static void main(String[] args) {
13
 	public static void main(String[] args) {
10
 		SpringApplication.run(BakeryApplication.class, args);
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 Прегледај датотеку

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

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

+ 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
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.GenerationType;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Baker {
9
 public class Baker {
10
+
11
+    @Id
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
4
     private Long id;
13
     private Long id;
5
 
14
 
6
     private String name;
15
     private String name;

+ 8
- 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.GenerationType;
6
+import javax.persistence.Id;
7
+
8
+@Entity
3
 public class Muffin {
9
 public class Muffin {
4
 
10
 
11
+    @Id
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
5
     private Long id;
13
     private Long id;
6
 
14
 
7
     private String flavor;
15
     private String flavor;

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

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

+ 4
- 0
src/main/resources/application-h2.properties Прегледај датотеку

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 Прегледај датотеку

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