[英]How do I pass in populated list as a parameter in an object constructor?
我有一個 java class,我正在設置它以在項目中存儲 LoL 冠軍,也使用 lombok(因此缺少 getter 和 setter)和 Z38008DD81C2F4D7985ECF6E0CE8AF1D1。 class 看起來像這樣:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Champion {
@Id
private String champName;
private String role;
private List<String> type; // <--- how do I populate this?
private String phrase;
private List<Champion> counterTo; //<--- or this?
private List<Champion> counteredBy;// <-- you get the idea.
}
我在我的主應用程序 class 中使用 commandLineRunner 覆蓋 spring 中的 run() 方法,但是當我使用 Spring 的.save() 方法調用構造函數時,我不知道如何填充列表。 任何人都可以幫忙嗎?
下面是主要的 class 的上下文:
public class PlaygroundApplication implements CommandLineRunner {
@Autowired ChampionRepository repo;
public static void main(String[] args) {
SpringApplication.run(PlaygroundApplication.class, args);
}
@Override
public void run(String...args){
repo.deleteAll();
//repo.save("CHAMPION_ENTITY_GOES_HERE);
}
}
如果我理解正確,您可以嘗試新的 object 並設置參數或自定義構造函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.