关联映射中的404错误 [英] 404 Error in Associate Mapping

查看:110
本文介绍了关联映射中的404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发购物车网络应用程序,该程序已完成显示产品以添加购物车。我试图将每个客户(一对一)映射到购物车实体,购物车实体(一对一)到购物车项目实体以及购物车项目实体(多对一)到产品实体。但我得到了404错误。
请检查下面的代码。

I am developing shopping cart web app which have completed up to display product to add cart. I am trying to map every customer (One To One) to cart Entity, cart entity (one to one) to cart item Entity, and cart item entity (Many to One) to Product entity. But I got a 404 error. Please check my code below.

客户-----一个到一个------>购物车----一对一---->购物车项目----多对一--->产品

Customer-----one to one------>Cart----one to one---->Cart Item----Many to one--->Product

package com.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;


@Entity
public class Customer {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Cid") 
private int customerId;
@Column(name="password")
@NotEmpty(message="Name is mandatory")
private String password;
@Column(name="Email") 
@NotEmpty(message="Name is mandatory")
private String email;
@NotEmpty(message="First Name is mandatory")
@Column(name="firstname")
private String firstName;
@NotEmpty(message="Last Name is mandatory")
@Column(name="lastname")
private String lastName;
@Column(name="Mobile")
@NotEmpty(message="Mobile is mandatory")
private String mobile;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="address_id")
private Address delAdderss;
private boolean enabled;
private String role;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="cart_id")
private Cart cart;

public Cart getCart() {
    return cart;
}
public void setCart(Cart cart) {
    this.cart = cart;
}
public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
public String getMobile() {
    return mobile;
}
public void setMobile(String mobile) {
    this.mobile = mobile;
}
public int getCustomerId() {
    return customerId;
}
public void setCustomerId(int name) {
    this.customerId = name;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public boolean isEnabled() {
    return enabled;
}
public void setEnabled(boolean enabled) {
    this.enabled = enabled;
}
public String getRole() {
    return role;
}
public void setRole(String role) {
    this.role = role;
}
public Address getDelAdderss() {
    return delAdderss;
}
public void setDelAdderss(Address delAdderss) {
    this.delAdderss = delAdderss;
}

}



购物车实体



Cart Entity

package com.model;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

@Entity
public class Cart {
@Id 
@GeneratedValue(strategy=GenerationType.AUTO)
    private int cart_id;
@Column
private double total;
@Column
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="item_id")
private CartItem cartItem;
public int getCart_id() {
return cart_id;
}
public void setCart_id(int cart_id) {
this.cart_id = cart_id;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public CartItem getCartItem() {
return cartItem;
}
public void setCartItem(CartItem cartItem) {
this.cartItem = cartItem;
}


}



购物车物品实体



Cart Item Entity

package com.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class CartItem {

@Id 
@GeneratedValue(strategy=GenerationType.AUTO)
private int item_id;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="id")
private List<Product> product;
public int getItem_id() {
return item_id;
}
public void setItem_id(int item_id) {
this.item_id = item_id;
}
public List<Product> getProduct() {
return product;
}
public void setProduct(List<Product> product) {
this.product = product;
}

}



产品实体



Product Entity

package com.model;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.springframework.web.multipart.MultipartFile;

@Entity
public class Product {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column
private String product_Name;
@Column
private String descripction;
@Column
private int price;
@Column
private Date mfg_Date;
@Transient
private MultipartFile image;

public MultipartFile getImage() {
return image;
}
public void setImage(MultipartFile image) {
this.image = image;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProduct_Name() {
return product_Name;
}
public void setProduct_Name(String product_Name) {
this.product_Name = product_Name;
}
public String getDescripction() {
return descripction;
}
public void setDescripction(String descripction) {
this.descripction = descripction;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Date getMfg_Date() {
return mfg_Date;
}
public void setMfg_Date(Date mfg_Date) {
this.mfg_Date = mfg_Date;
}
}


推荐答案

您是否使用购物车项目实体,根据我的说法,它应该是与购物车一对一的客户,并且与购物车成为一对一。我认为不需要购物车物品表/实体。

Why are you using cart item entity, According to me it should be Customer one on one with Cart, And a Cart as one to many with Products. I think there is no need for cart items table/entity.

这篇关于关联映射中的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆