插入包含多行的表格。以下是
的描述HTML:
<tr>
<td><input type="text" name="description"/></td>
<td><input type="text" name="quantity" /></td>
<td><input type="text" name="price" /></td>
<td><input type="text" name="lineTotal" /></td>
</tr>
<tr>
<td><input type="text" name="description"/></td>
<td><input type="text" name="quantity" /></td>
<td><input type="text" name="price" /></td>
<td><input type="text" name="lineTotal" /></td>
</tr>
DBManager
public static void invoiceDescription(
long invoiceId, String description, int quantity,
int price, int lineTotal){
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
//String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String sql = "INSERT INTO invoice_description"
+ "(descId, invoiceId, description, quantity, price, total) VALUES"
+ "(NULL,?,?,?,?,?)";
try {
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(sql);
preparedStatement.setLong(1, invoiceId);
preparedStatement.setString(2, description);
preparedStatement.setInt(3, quantity);
preparedStatement.setInt(4, price);
preparedStatement.setInt(5, lineTotal);
preparedStatement.executeUpdate();
System.out.println("You have successfully added descriptions to invoice");
} catch (SQLException e){
System.out.println(e.getMessage());
}
}
控制器:
@RequestMapping(value = "/invoice", method = RequestMethod.POST)
public String submitInvoice(HttpServletRequest request,
@RequestParam("clients") int clientId,
@RequestParam("invoice_date") String invoice_date,
@RequestParam("invoice_due_date") String invoice_due_date,
@RequestParam("status") String status,
@RequestParam("payment_method") String payment_method,
@RequestParam("currency") String currency,
@RequestParam("description") String description,
@RequestParam("quantity") int quantity,
@RequestParam("price") int price,
@RequestParam("lineTotal") int lineTotal) {
if(!hasRole(request, "ROLE_USER")){
return "403";
}
long invoiceId = DBManager.createInvoice(clientId, invoice_date, invoice_due_date, status, payment_method, currency);
DBManager.invoiceDescription(invoiceId, description, quantity, price, lineTotal);
return "redirect:/createInvoice";
}
您好。我试图将具有相同输入名称的数据插入invoice_description表。它插入时没有任何错误,但不是多行。我的目标是拥有多个具有唯一ID的行,但特定发票号的invoiceId(FK)相同。
请帮忙