我正在创建一个调查项目,Survey有一些选择题。对于调查和问题,我有一个班级,
@Entity
public class SurveyEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private String surveyId;
private String title;
private String description;
private List<QuestionEntity> questions;
}
@Entity
public class QuestionEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private String questionId;
private String description;
private String correctAns;
private List<String> options;
}
我想在项目启动时预先填充数据。所以我写了一个sql文件(initial.sql
)并将其放入Spring Boot的application.properties
,
insert into SurveyEntity(surveyId, title, description) values("Survey1", "Collected Survey", "description of the survey1");
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question1", "Largest Country in the World", "Russia", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question2", "Most populous Country in the World", "China", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question3", "Highest GDP in the World", "United States", ??);
insert into QuestionEntity(questionId, description, correctAns, ?) values ("Question4", "Second largest English speaking country", "India", ??);
我的问题是,如何使用上述语句填充字符串列表(options
已提交)?或者我是否需要为options
创建一个单独的表?