我目前正在開發一個配方應用程式,但在生成資料庫表時遇到了問題。
這是我正在使用的物體檔案:
// Recipe.java
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "recipes")
public class Recipe {
@Id
@GeneratedValue
private int id;
private String name;
private String description;
private String instruction;
@ManyToOne
private User user;
@OneToMany(cascade=CascadeType.ALL)
private List<RecipeIngredient> ingredients = new ArrayList<>();
}
// Ingredient.java
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "ingredients")
public class Ingredient {
@Id
@GeneratedValue
private int id;
private String name;
}
// RecipeIngredient.java
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
public class RecipeIngredient {
@Id
@GeneratedValue
private int id;
@ManyToOne
private Ingredient ingredient;
private String amount;
}

Spring Boot 自動為我創建表,但我只想為 RecipeIngredient 創建一個表,但它為它們創建了兩個表。它作業得很好,但我想要的只是如何將這兩個表合二為一,或者讓 spring boot 不生成其中一個。
uj5u.com熱心網友回復:
如果你想要 recipe_ingedients 表只洗掉 recipeIngredient 物體類,如果你想保留 recipe_ingredient 表洗掉這個:
@OneToMany(cascade=CascadeType.ALL)
private List<RecipeIngredient> ingredients = new ArrayList<>();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/514380.html
標籤:爪哇春天弹簧靴jpah2
