From 2d8b87cb5be3eb00c49d8534f047d15b8795fd06 Mon Sep 17 00:00:00 2001 From: Chantha Date: Mon, 18 May 2020 14:51:58 +0700 Subject: [PATCH] Relation Database --- .idea/workspace.xml | 68 +++++++++--------- pom.xml | 7 ++ .../com/chantha/jdbc/config/WebConfig.java | 4 ++ .../jdbc/controller/ProductController.kt | 2 + .../com/chantha/jdbc/jpa/model/Customer.java | 1 + .../com/chantha/jdbc/jpa/model/Order.java | 16 ++++- .../com/chantha/jdbc/jpa/model/Position.java | 25 +++++++ .../com/chantha/jdbc/jpa/model/Staff.java | 33 +++++++++ .../jdbc/controller/ProductController.class | Bin 2180 -> 2180 bytes .../com/chantha/jdbc/jpa/model/Order.class | Bin 3322 -> 3774 bytes .../com/chantha/jdbc/jpa/model/Position.class | Bin 0 -> 3348 bytes .../com/chantha/jdbc/jpa/model/Staff.class | Bin 0 -> 5432 bytes 12 files changed, 123 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/com/chantha/jdbc/config/WebConfig.java create mode 100644 src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java create mode 100644 src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java create mode 100644 target/classes/com/chantha/jdbc/jpa/model/Position.class create mode 100644 target/classes/com/chantha/jdbc/jpa/model/Staff.class diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5bdc19a..15b2bba 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,16 @@ - + + + + - - - + + - + @@ -49,7 +51,7 @@ - + @@ -86,7 +88,9 @@ - + + + @@ -102,65 +106,65 @@ - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index d70d3ce..b9b4b07 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,13 @@ 42.2.12 + + + org.springframework.boot + spring-boot-starter-security + 2.3.0.RELEASE + + org.jetbrains.kotlin kotlin-reflect diff --git a/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java b/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java new file mode 100644 index 0000000..cc1a322 --- /dev/null +++ b/src/main/kotlin/com/chantha/jdbc/config/WebConfig.java @@ -0,0 +1,4 @@ +package com.chantha.jdbc.config; + +public class WebConfig { +} diff --git a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt index 87c1181..6ddcdbb 100644 --- a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt +++ b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt @@ -5,6 +5,7 @@ import com.chantha.jdbc.jpa.model.view.ProductWithOrderDetail import com.chantha.jdbc.jpa.repo.ProductRepo import com.chantha.jdbc.jpa.service.product.ProductService import org.springframework.beans.factory.annotation.Autowired +import org.springframework.web.bind.annotation.CrossOrigin import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController @@ -15,6 +16,7 @@ public class ProductController @Autowired constructor(private val productService fun product():List{ return productService.fetchAllProducts() } + @GetMapping("/api/product/getproduct") fun getAllProduct():List{ return productRepo.readAllRecord() diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java index 68f3841..015bd9b 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Customer.java @@ -72,4 +72,5 @@ public class Customer implements Serializable { @JsonManagedReference @OneToMany(mappedBy = "customer") private List orders; + } diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java index 9a1ca4a..b7bf864 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Order.java @@ -31,6 +31,11 @@ public class Order implements Serializable { @JoinColumn(name = "cusId",nullable = false,referencedColumnName = "id") private Customer customer; + @ManyToOne(fetch = FetchType.LAZY) + @JsonBackReference + @JoinColumn(name = "sid",nullable = false,referencedColumnName = "id") + private Staff staff; + @OneToMany(mappedBy = "order") private List orderDetails; @@ -39,6 +44,14 @@ public class Order implements Serializable { return orderId; } + public Staff getStaff() { + return staff; + } + + public void setStaff(Staff staff) { + this.staff = staff; + } + public void setOrderId(Long orderId) { this.orderId = orderId; } @@ -80,10 +93,11 @@ public class Order implements Serializable { public Order() { } - public Order(Long orderId,Date orderDate,double amount,Customer customer,List orderDetails) { + public Order(Long orderId,Date orderDate,double amount,Customer customer,List orderDetails,Staff staff) { this.orderId=orderId; this.orderDate=orderDate; this.amount=amount; this.orderDetails=orderDetails; + this.staff=staff; } } diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java new file mode 100644 index 0000000..ac9bb52 --- /dev/null +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java @@ -0,0 +1,25 @@ +package com.chantha.jdbc.jpa.model; + +import com.fasterxml.jackson.annotation.JsonManagedReference; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.List; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Position { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String tittle; + + @OneToMany(mappedBy = "position") + @JsonManagedReference + private List staff; +} diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java new file mode 100644 index 0000000..407d7f0 --- /dev/null +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java @@ -0,0 +1,33 @@ +package com.chantha.jdbc.jpa.model; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonManagedReference; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.util.List; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Staff { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private Gender gender; + private double salary; + + + @JsonManagedReference + @OneToMany(mappedBy = "staff") + private List orderList; + + @JsonBackReference + @ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL) + @JoinColumn(name = "posId",nullable = false,referencedColumnName = "id") + private Position position; +} diff --git a/target/classes/com/chantha/jdbc/controller/ProductController.class b/target/classes/com/chantha/jdbc/controller/ProductController.class index 0cafbee67df06ceb797e385bbdbcc7303fa50155..95d7dd353b4733bb61769ca21f8747a68dff6336 100644 GIT binary patch delta 29 jcmZn>Y!TdWn~hO$@*TEJMlm2MIXRv^k&$=uLH5G{lM4yg delta 29 jcmZn>Y!TdWn~hOm@*TEJMiC$>IXRv^k&$QeLH5G{lG6#( diff --git a/target/classes/com/chantha/jdbc/jpa/model/Order.class b/target/classes/com/chantha/jdbc/jpa/model/Order.class index be4a4c8d65d0cab900239524d6e14faf35c9ca82..4d5ba025edb99561ac95b0bc05493aa8a3e91675 100644 GIT binary patch literal 3774 zcmcImYjYE26h514n?{RJt3fUiLDFzp6p%{`QW`GBw1qZSse-)OeUolYc00Qp2lV&& zS)8%Mj34{~{wT-iyt~;Z+id`6{E*%EaxTw#&SmrWKY#v3M3=}Kr!o40AJ6z9_|fEt z!4I=Q<0SLc%2PW}n;PXE*Ocy}snLP@miS5N9bvcix?{IzH7c$4Y~Sk2b<4Aw9XW5? zjxT)6u|18ZmH2agTe_a*`O-F|zGy<}M8d^AX-il5(p(pvo`let=kvb(Vx&AgHC}8h z`Ni6u<;G&;u}0$xaShrL=ALhLbUuOQYjwlv>Ma3C?(=R(-x9`;o@48#@I}+IO5lXZ}u&H)}%M! zRe!y=0R{G#6I}!C&VsU|7b#rmW2JH;jGw-hnDmW z6i1TWUA_vllBv&cAS0Ld2|vd4ZDe9qwxr9o0u;v*P&{xfd%@}Sx;6wdw&)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