【问题标题】:How to select all inputs having same name insert into Mysql?如何选择所有具有相同名称的输入插入Mysql?
【发布时间】:2016-07-05 23:58:11
【问题描述】:

如何将具有相同名称的表单多个输入插入Mysql?我试过在Mysql中插入三个同名的select选项,但是提交的时候都变成了一列,每个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;
}

这是我的休眠(创建)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();

    }
}

【问题讨论】:

  • 字体标签已弃用
  • 对不起,我错过了!!

标签: java html mysql hibernate jsp


【解决方案1】:

您的第一个错误是您的第一个选择标签应该在字体标签内部或外部,因为您以错误的方式关闭它。其次,将整个 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 个选择标签到 html 将占用比 Json 多 100 倍的空间。根据我的计算,我保存了大约 100 万条记录,占用了大约 1 Gb 空间

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 2022-07-13
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    相关资源
    最近更新 更多