我试图对字符串列表进行字符串化,并JSON使用hibernate将其存储在mysql中,其格式为:
List<String> options = new ArrayList<>();
String first = "What is your name?";
options.add(first);
String option = objectMapper.writeValueAsString(options);
// option value is: ["what is your name?"]
我的表结构:
CREATE TABLE question(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
label VARCHAR(150) NULL,
question_type VARCHAR(200) NULL,
mandatory TINYINT DEFAULT 0,
editable TINYINT DEFAULT 0,
`option` JSON NULL
);
实体:
@Entity
@Table(name = "question")
public class Question implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2209760405736391727L;
private int id;
private String label;
private QuestionType questionType;
private boolean mandatory;
private boolean editable;
private String options;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "label")
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@Column(name = "question_type")
@Enumerated(EnumType.STRING)
public QuestionType getQuestionType() {
return questionType;
}
public void setQuestionType(QuestionType questionType) {
this.questionType = questionType;
}
@Column(name = "mandatory")
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
@Column(name = "editable")
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
@Column(name = "option")
public String getOptions() {
return options;
}
public void setOptions(String options) {
this.options = options;
}
}
拉丁的传说
相关分类