복붙노트

[SPRING] 404 연관 매핑 오류

SPRING

404 연관 매핑 오류

나는 장바구니를 추가하기 위해 제품을 완성하기 위해 완성한 장바구니 웹 앱을 개발 중입니다. 카트 엔티티, 장바구니 엔티티 (일대일), 장바구니 항목 엔터티 및 장바구니 항목 엔터티 (일대일)를 제품 엔터티에 매핑하려고합니다. 하지만 404 오류가 발생했습니다. 아래 코드를 확인하십시오.

고객 ----- 일대일 ------> 장바구니 ---- 일대일 ----> 장바구니 항목 ---- 다 대일 ---> 제품

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;
}

}
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;
}


}
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;
}

}
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;
}
}

해결법

  1. ==============================

    1.왜 당신은 장바구니 항목 엔티티를 사용하고 있습니까, 나에 따르면 그것은 하나의 장바구니와 함께 카트와 장바구니에 제품과 함께 하나씩해야합니다. 카트 항목 테이블 / 엔티티가 필요 없다고 생각합니다.

    왜 당신은 장바구니 항목 엔티티를 사용하고 있습니까, 나에 따르면 그것은 하나의 장바구니와 함께 카트와 장바구니에 제품과 함께 하나씩해야합니다. 카트 항목 테이블 / 엔티티가 필요 없다고 생각합니다.

  2. from https://stackoverflow.com/questions/43187799/404-error-in-associate-mapping by cc-by-sa and MIT license