我想知道如何使用 Struts2 将多个具有相同名称的数据同时保存到我的数据库中以下
public String createPO() {
if (isAuthorizedUser(authorizedUsers)) {
dao = HibernateDAOFactory.getInstance();
order = new OrderEntity()
order.setQuantity(quantity);
order.setAmount(amount);
order.setDescription(description);
order.setUnit(unit);
order.setUnitPrice(unitPrice);
order.setUser(user);
System.out.println(order.getOrderid());
dao.getOrderDAO().isSaved(order);
return SUCCESS;
}
return logout();
}
这是我的 JSP 页面。单击添加按钮后,它将创建另一个具有相同名称的字段。
<table id="orderTable" class="table table-bordered">
<tr>
<td style="background-color: #40926f; color: white;"><strong><center>Quantity</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Unit</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Description</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Unit Price</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Amount</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Add</center></strong></td>
<td style="background-color: #40926f; color: white;"><strong><center>Delete</center></strong></td>
</tr>
<tr id="orderDetailsTr" class="order">
<td>
<center>
<input required style="height: 35px; width: 100px;" type="text" placeholder="QTY"
name="quantity"
id="quantity" class="quantity" >
</center>
</td>
<td>
<center>
<input required style="height: 35px; width: 200px;" type="text" placeholder="Unit"
name="unit"
id="unit" >
</center>
</td>
<td>
<center>
<input required style="height: 35px; width: 300px;" type="text" placeholder="Description"
name="description"
id="description" >
</center>
</td>
<td>
<center>
<input required style="height: 35px; width: 100px;" type="text" placeholder="Unit Price"
name="unitPrice"
id="unitPrice" class="unitPrice" >
</center>
</td>
<td>
<center>
<input required style="height: 35px; width: 100px;" type="text" placeholder="Amount"
name="amount"
id="amount" class="amount" >
</center>
</td>
<td><input type="button" class="btn btn-primary" id="addmorePOIbutton" value="Add"/></td>
</tr>
</table>