如何将具有相同名称的多个输入表单插入到Mysql中?我已经尝试在Mysql中插入三个相同的名称选择选项,但是当提交时,所有变成一列,每个questionid都有自己的分数,例如,我在mysql中有三个questionid列,每列都有自己的分数,所以它对于每个questionid可能有三个得分列,就像这样----> enter image description here我有这样的问题-----> enter image description here !!
jsp代码:
<form id="result" role="form" class="form-inline" action="mature.htm" method="post">
<select name="score" class="form-control input-lg">
<font>
<option value="1">○</option>
<option value="2">△</option>
<option value="3">×</option></select>
</font>
<font size="5"><select name="score" class="form-control input-lg">
<option value="1">○</option>
<option value="2">△</option>
<option value="3">×</option></select>
</font>
<font size="5"><select name="score" class="form-control input-lg">
<option value="1">○</option>
<option value="2">△</option>
<option value="3">×</option></select>
</font>
实体模型:Result.java
@Column(name="score", length=45)
public String getScore() {
return this.score;
}
public void setScore(String score) {
this.score = score;
}
这是我的hibernate(创建)DEO:
public void create2(Result e,Result e2)
{
try{
Session s=HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();
e.setQuestionid("lokesh@mail.com");
s.save(e);
s.getTransaction().commit();
Session s2=HibernateUtil.getSessionFactory().getCurrentSession();
s2.beginTransaction();
e2.setQuestionid("l.com");
s2.save(e2);
s2.getTransaction().commit();
}catch(Exception ex){
ex.printStackTrace();
}
}
答案 0 :(得分:0)
您的第一个错误是您的第一个选择标记应该在字体标记内部或外部,因为您正以错误的方式关闭它。其次,将整个HTML存储在数据库中是一种不好的做法,因为它比仅保存密钥和值消耗更多的空间。 在我的情况下,我保存了这样的:
{"q":[{"qid":"Do you solve the issue?","answer":{"1":"yes"}},{"qid":"what was the issue?","answer":["credit card problem"]}]}
我从html中检索上面提到的json,类似于:
<label id="lbl1">do you solve the issue?</label>
<input type="radio" name="qid1" value="yes">Yes<br>
<input type="radio" name="qid1" value="no">No<br>
<label id="lbl1">what was the issue?</label>
<select id="qid1">
<option value="1">credit card problem</option>
<option value="2">dedit card problem</option>
</select>
你可以看到第一个问题是只保存一个答案,第二个问题是保存数组,可以保存选择标签的多个答案。
将5个select标签保存到每个用户的html将占用比Json多100倍的空间。根据我的计算,我节省了大约100万条记录,占用了大约1 Gb空间