我正在为我的大学项目开发一个电子商务网站(spring MVC、Java、mySql、Hibernate)。我有各种模型,如客户,产品,订单,客户历史等。
我能够显示所有客户的详细信息(在管理页面)和所有产品供客户浏览。
但我面临的问题是,我如何展示一个客户的订单和订单历史?
我的orders表有orderId、productId、quantity和total Price。但是要显示产品名,我必须使用productId并从product表中重新创建产品名。
我对如何做这件事毫无头绪。
到目前为止,我一直在使用jstl foreach循环迭代ProductList.jsp页面中的产品,并将它们显示在一个表中。但是如上所述,我需要同时从3-4个表中检索数据,例如productName(来自product表)、productManuacturer(也来自product表)、ShippingAddress(来自customer表)。我不知道该怎么做。
编辑1:我从别人的电脑上问这个问题,当时没有带我的代码。所以,我在这里给出我的代码。
>
customer.java
package com.site.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.NotEmpty;
import javax.persistence.*;
import java.io.Serializable;
@Entity
public class Customer implements Serializable {
private static final long serialVersionUID = -3280023076408333682L;
@Id
@GeneratedValue
private int customerId;
@NotEmpty(message = " The customer name must not be blank.")
private String customerName;
@NotEmpty (message = " The customer email must not be blank.")
private String customerEmail;
private String customerPhone;
@NotEmpty (message = " The username must not be blank.")
private String username;
@NotEmpty (message = " The password must not be blank.")
private String password;
private boolean enabled;
@OneToOne
@JoinColumn(name = "billingAddressId")
private BillingAddress billingAddress;
@OneToOne
@JoinColumn(name = "shippingAddressId")
private ShippingAddress shippingAddress;
@OneToOne()
@JoinColumn(name = "cartId")
@JsonIgnore
private Cart cart;
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public BillingAddress getBillingAddress() {
return billingAddress;
}
public void setBillingAddress(BillingAddress billingAddress) {
this.billingAddress = billingAddress;
}
public ShippingAddress getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(ShippingAddress shippingAddress) {
this.shippingAddress = shippingAddress;
}
public String getCustomerPhone() {
return customerPhone;
}
public void setCustomerPhone(String customerPhone) {
this.customerPhone = customerPhone;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Cart getCart() {
return cart;
}
public void setCart(Cart cart) {
this.cart = cart;
}
}
cart.java
软件包com.site.model;
导入com.fasterxml.jackson.annotation.jsonIgnore;
导入javax.persistence.*;导入java.io.Serializable;导入java.util.ArrayList;导入java.util.List;
@Entity公共类购物车实现Serializable{
专用静态最终长serialVersionUID=-2479653100535233857L;
@id@GeneratedValue private int CartId;
@OneTomany(mappedBy=“Cart”,Cascade=CascadeType.All,fetch=FetchType.Eager)私有列表cartItems=new ArrayList();
@OneToOne@JoinColumn(name=“CustomerID”)@JsonIgnore private Customer;
私人双大;
public int getCartId(){return CartId;}
public void setCartId(int cartId){this.cartId=cartId;}
公共双倍getGrandTotal(){return GrandTotal;}
public void setGrandTotal(double grandTotal){This.grandTotal=grandTotal;}
公共列表getCartItems(){return Cartitems;}
public void setCartItems(List cartItems){this.cartItems=cartItems;}
公用客户getCustomer(){return Customer;}
public void setCustomer(Customer Customer){this.Customer=Customer
}
cartitem.java
package com.site.model;
导入com.fasterxml.jackson.annotation.jsonIgnore;
导入javax.persistence.*;导入java.io.Serializable;导入java.util.List;
@Entity公共类CartItem实现Serializable{
private static final long serialVersionUID = -904360230041854157L;
@Id
@GeneratedValue
private int cartItemId;
@ManyToOne
@JoinColumn(name="cartId")
@JsonIgnore
private Cart cart;
@ManyToOne
@JoinColumn(name = "productId")
private Product product;
private int quantity;
private double totalPrice;
@ManyToMany(cascade=CascadeType.ALL, mappedBy="cartItems")
@JsonIgnore
private List<OrderHistory> orderHistoryList;
public int getCartItemId() {
return cartItemId;
}
public void setCartItemId(int cartItemId) {
this.cartItemId = cartItemId;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public Cart getCart() {
return cart;
}
public void setCart(Cart cart) {
this.cart = cart;
}
public List<OrderHistory> getOrderHistoryList() {
return orderHistoryList;
}
public void setOrderHistoryList(List<OrderHistory> orderHistoryList) {
this.orderHistoryList = orderHistoryList;
}
}
customerorder.java
package com.site.model;
导入javax.persistence.*;导入java.io.Serializable;
@Entity公共类CustomerOrder实现Serializable{
private static final long serialVersionUID = -3608286390950243118L;
@Id
@GeneratedValue
private int customerOrderId;
@OneToOne
@JoinColumn(name = "cartId")
private Cart cart;
@OneToOne
@JoinColumn(name = "customerId")
private Customer customer;
@OneToOne
@JoinColumn(name = "billingAddressId")
private BillingAddress billingAddress;
@OneToOne
@JoinColumn(name = "shippingAddressId")
private ShippingAddress shippingAddress;
public int getCustomerOrderId() {
return customerOrderId;
}
public void setCustomerOrderId(int customerOrderId) {
this.customerOrderId = customerOrderId;
}
public Cart getCart() {
return cart;
}
public void setCart(Cart cart) {
this.cart = cart;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public BillingAddress getBillingAddress() {
return billingAddress;
}
public void setBillingAddress(BillingAddress billingAddress) {
this.billingAddress = billingAddress;
}
public ShippingAddress getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(ShippingAddress shippingAddress) {
this.shippingAddress = shippingAddress;
}
}
OrderHistory.java
软件包com.site.model;
导入javax.persistence.*;导入java.io.Serializable;导入java.util.ArrayList;导入java.util.List;
@Entity公共类OrderHistory实现Serializable{
private static final long serialVersionUID = 1083533250613139445L;
@Id
@GeneratedValue
private int orderHistoryId;
private int customerId;
private String customerName;
private int customerOrderId;
private int cartId;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "cartItem_orderHistory", joinColumns = @JoinColumn(name = "orderHistoryId"),
inverseJoinColumns = @JoinColumn
(name = "cartItemId"))
private List<CartItem> cartItems = new ArrayList<CartItem>();
private double grandTotal;
private String billingAddress;
private String shippingAddress;
public int getOrderHistoryId() {
return orderHistoryId;
}
public void setOrderHistoryId(int orderHistoryId) {
this.orderHistoryId = orderHistoryId;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public int getCustomerOrderId() {
return customerOrderId;
}
public void setCustomerOrderId(int customerOrderId) {
this.customerOrderId = customerOrderId;
}
public int getCartId() {
return cartId;
}
public void setCartId(int cartId) {
this.cartId = cartId;
}
public List<CartItem> getCartItems() {
return cartItems;
}
public void setCartItems(List<CartItem> cartItems) {
this.cartItems = cartItems;
}
public double getGrandTotal() {
return grandTotal;
}
public void setGrandTotal(double grandTotal) {
this.grandTotal = grandTotal;
}
public String getBillingAddress() {
return billingAddress;
}
public void setBillingAddress(String billingAddress) {
this.billingAddress = billingAddress;
}
public String getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(String shippingAddress) {
this.shippingAddress = shippingAddress;
}
}
编辑2:如何将数据存储在ustomerorder表和orderhistory表中,以及如何在jsp页面上显示数据?
您的订单表中应该有customerid。以便您可以通过提供CustomerID来获取客户的订单历史记录。
您应该在order表中有一个CustomerId列,用于检测与哪个客户关联的订单。只需在其中插入logged in userid,并通过与customer表建立join来获取客户名称。
我正在Laravel4上使用lib PayPal PHP SDK 我对显示订单细节有意见。我按照贝宝网络结账的步骤操作,它没有向我显示订单细节。 这是当我得到支付链接的方法:
我正在搜索和尝试它2天没有成功,请帮助。 我想筛选woocommerce订单,以便根据产品属性将其他详细信息从db添加到订单详细信息页面,但我找不到适合此任务的woocommerce操作/筛选器挂钩。这里假设变量; 如果,那么我需要将自定义数据从数据库添加到订单详细信息页面。 注意:我不想添加额外的元框,而是想更改订单明细表: 将默认产品映像替换为存储在数据库和中的映像, 在产品名称下面添加包含自
我使用以下代码在WooCommerce管理订单详细信息页面的订单项表中显示自定义产品元: 它显示“前缀tempiconsegna”,这是自定义图元,如: 可在3天内提供 我的问题是,如果我改变了产品的可用性,它也改变了以前的订单。 当我更新产品的可用性时,如何在不改变的情况下显示订单时的值?
上次WooCommerce更新后,订单详细信息不再显示在感谢页面上。从那时起,我使用WooCommerce Storefront主题开发了一个儿童主题。不管我做了什么,我看到的只是感谢页面上的“谢谢”信息。 到目前为止我所尝试的: > 对整个进程进行故障排除,以查找任何可能出错的问题。这包括以下内容: 检查了调用order-details模板和it相关操作挂钩的wc模板函数(均存在) 确保我的Ch
我用ACF插件创建了一个高级定制字段,以便在Woocommerce产品编辑页面上添加附加信息。这是一个区分T恤模板的副标题。我能够使价值出现在产品页面前端,但我需要这些信息出现在订单细节和所有电子邮件中,也许作为订单元。提前谢了。