我需要知道Html如何将几个多选同名插入到mysql中?我得到这个问题 - > enter image description here所有插入到一个字段中,那些得分选项1应该是多行,而不仅仅是一列!我希望这样 - > enter image description here有人可以告诉我该怎么办?
我使用java(spring),hibernate,mysql作为工具。
请帮助我!!!!
这是我的jsp代码:
<form id="result" role="form" class="form-inline" action="mature.htm" here`method="post">
<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>
<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>
这是我的实体模型:
public class Result implements java.io.Serializable {
private Integer no;
private String username;
private String questionid;
private String score;
public Result() {
}
public Result(String username, String questionid, String score) {
this.username = username;
this.questionid = questionid;
this.score = score;
}
@Id @GeneratedValue(strategy=IDENTITY)
@Column(name="no", unique=true, nullable=false)
public Integer getNo() {
return this.no;
}
public void setNo(Integer no) {
this.no = no;
}
@Column(name="username", length=45)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name="questionid", length=255)
public String getQuestionid() {
return this.questionid;
}
public void setQuestionid(String questionid) {
this.questionid = questionid;
}
@Column(name="score", length=45)
public String getScore() {
return this.score;
}
public void setScore(String score) {
this.score = score;
}
这是我的hbm.xml:
<hibernate-mapping>
<class name="entity.Result" table="result" catalog="companyresources" optimistic-lock="version">
<id name="no" type="java.lang.Integer">
<column name="no" />
<generator class="identity" />
</id>
<property name="username" type="string">
<column name="username" length="45" />
</property>
<property name="questionid" type="string">
<column name="`questionid`" length="255" />
</property>
<property name="score" type="string">
<column name="score" length="45" />
</property>
</class>
这是我的java控制器:
@RequestMapping(value="/mature",method=RequestMethod.POST)
public String create2(@ModelAttribute(value="result")Result e,Result e2,Model m)
{
CompanyModel model=new CompanyModel();
model.create2(e,e2);
m.addAttribute("list",model.getID());
m.addAttribute("lst2",model.getAll2());
m.addAttribute("list",model.getID2());
return"redirect:question.htm";
}