Relation Database
This commit is contained in:
4
src/main/kotlin/com/chantha/jdbc/config/WebConfig.java
Normal file
4
src/main/kotlin/com/chantha/jdbc/config/WebConfig.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.chantha.jdbc.config;
|
||||
|
||||
public class WebConfig {
|
||||
}
|
||||
@@ -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<ProductWithOrderDetail>{
|
||||
return productService.fetchAllProducts()
|
||||
}
|
||||
|
||||
@GetMapping("/api/product/getproduct")
|
||||
fun getAllProduct():List<Product>{
|
||||
return productRepo.readAllRecord()
|
||||
|
||||
@@ -72,4 +72,5 @@ public class Customer implements Serializable {
|
||||
@JsonManagedReference
|
||||
@OneToMany(mappedBy = "customer")
|
||||
private List<Order> orders;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<OrderDetail> 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<OrderDetail> orderDetails) {
|
||||
public Order(Long orderId,Date orderDate,double amount,Customer customer,List<OrderDetail> orderDetails,Staff staff) {
|
||||
this.orderId=orderId;
|
||||
this.orderDate=orderDate;
|
||||
this.amount=amount;
|
||||
this.orderDetails=orderDetails;
|
||||
this.staff=staff;
|
||||
}
|
||||
}
|
||||
|
||||
25
src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java
Normal file
25
src/main/kotlin/com/chantha/jdbc/jpa/model/Position.java
Normal file
@@ -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> staff;
|
||||
}
|
||||
33
src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java
Normal file
33
src/main/kotlin/com/chantha/jdbc/jpa/model/Staff.java
Normal file
@@ -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<Order> orderList;
|
||||
|
||||
@JsonBackReference
|
||||
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "posId",nullable = false,referencedColumnName = "id")
|
||||
private Position position;
|
||||
}
|
||||
Reference in New Issue
Block a user