[英]How to save multiple tables using Spring Boot JpaRepository and their MySQL script
//餐廳實體類
public class Restaurant {
@GeneratedValue
@Id
private Long id;
@NotBlank
@Size(min = 3, max = 50)
private String name;
@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
private List<Menu> menus;
}
//菜單實體類
public class Menu {
@Id
private Long id;
@NotBlank
@Size(min = 3, max = 50)
private String type;
@NotBlank
private String info;
@ManyToOne
@JoinColumn(name = "restaurant_id")
private Restaurant restaurant;
}
我有兩個實體:一個是餐廳,另一個是帶有終點的菜單
/餐廳
GET - get all restaurants
POST - upload restaurant
PUT - Update restaurant
DELETE - delete all restaurant
/餐廳/ {id}
GET - get a restaurant by id
DELETE - delete a restaurant by id
/ restaurants / {id} / menus /
GET - get all menus in the restaurant specified by id
POST - add new menus in the restaurant specified by id
DELETE - delete all menus in the restaurant specified by id
現在,您能否檢查一下實體類是否正確,並向我提供上述實體的MySQL腳本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.