Я хочу сохранить список продуктов в базе данных после нажатия кнопки заказа, он не сохраняется. Я использовал идентификатор клиента, идентификатор продукта, идентификатор корзины, но не сохранил в базе данных.
проверьте мой код orderContoller ..
Корзина. jsp
<form:form action="/order" method="POST" modelAttribute="orderModel">
<table class="table table-striped table-hover table-bordered">
<c:forEach items="${listCart}" var="items" varStatus="status">
<tr>
<td><form:checkbox path="${items.id}" /></td>
<td style="text-align: center">${items.id}</td>
<td style="text-align: center">${items.name}</td>
<td style="text-align: center"><fmt:formatNumber type="currency">${items.price}
</fmt:formatNumber></td>
<td>
</tr>
</c:forEach>
</table>
<div class="col-md-5">
<a class="btn btn-light btn-xl" href=" ">Order Now!</a>
</div>
</form:form>
orderController.class
@RequestMapping("/order")
public ModelAndView createOrder() {
customerOrderModel customerOrder = new customerOrderModel();
Cart cart = cartdao.getCartByID(id);
customerOrder.setCart(cart);
CustomerModel customer = cart.getCustomer();
customerOrder.setCustomerID(customer);
customerOrder.setBillingAddress(customer.getBillingAddress());
customerOrder.setShippingAddress(customer.getShippingAddress());
orderDao.addCustomerOrder(customerOrder);
return new ModelAndView("Cart","orderModel",new customerOrderModel());
Cart.class
@Entity
public class Cart {
@Id
@GeneratedValue
private int id;
private String name;
private BigDecimal price;
private int quantity;
private CustomerModel customer;
Это класс модели клиента.
CustomerModel.class
@Entity
public class CustomerModel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name="ID")
private int CustomerID;
@Column(name="First_Name")
private String customerFName;
@Column(name="Last_Name")
private String customerLName;
@Column(name="Email")
private String customerEmail;
@Column(name="Password")
private String customerPassword;
@Column(name="Contact")
private String customerContact;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "billingAddressId")
private BillingAddress billingAddress;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "shippingAddressId")
private ShippingAddress shippingAddress;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Cartid")
private Cart cart;
CustomerOrderModel.class
@Entity
public class customerOrderModel {
@Id
@GeneratedValue
private String OrderID;
@OneToOne
@JoinColumn(name="ID")
private CustomerModel customerID;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "billingAddressId")
private BillingAddress billingAddress;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "shippingAddressId")
private ShippingAddress shippingAddress;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Cartid")
private Cart cart;