TODO:bug fix

This commit is contained in:
myh 2023-11-10 16:48:23 +08:00
parent c6e1ec0771
commit d248755b28
8 changed files with 22 additions and 26 deletions

View File

@ -26,8 +26,7 @@ public class Dishes {
private BigDecimal finalPrice;//菜品最终价格 private BigDecimal finalPrice;//菜品最终价格
private String description;//菜品描述 private String description;//菜品描述
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "merchantsID", referencedColumnName = "id") @JoinColumn(name = "merchantsID", referencedColumnName = "id")
@Column(name = "merchantsID")
private Merchants merchants;//商家 private Merchants merchants;//商家
} }

View File

@ -3,6 +3,7 @@ package com.example.springdemo.entities;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.*; import lombok.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Data @Data
@ -23,6 +24,5 @@ public class Merchants {
//商家和菜品是一对多的关系有mappedBy的时候表示Merchants的dishes 字段放弃维护权而将维护权交给了Dishes的关联属性merchants //商家和菜品是一对多的关系有mappedBy的时候表示Merchants的dishes 字段放弃维护权而将维护权交给了Dishes的关联属性merchants
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "merchants") @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "merchants")
@Column(name = "dishesID") private List<Dishes> dishes = new ArrayList<>();//菜品
private List<Dishes> dishes;//菜品
} }

View File

@ -19,15 +19,14 @@ public class OrderDishes {
private Long id;//主键ID private Long id;//主键ID
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "dishesID", referencedColumnName = "id") @PrimaryKeyJoinColumn(name = "dishesID", referencedColumnName = "id")
@Column(name = "dishesID")
private Dishes dishes;//菜品ID private Dishes dishes;//菜品ID
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "merchantsID", referencedColumnName = "id") @PrimaryKeyJoinColumn(name = "merchantsID", referencedColumnName = "id")
private Merchants merchants;//商家ID private Merchants merchants;//商家ID
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "ordersID", referencedColumnName = "id") @JoinColumn(name = "ordersID", referencedColumnName = "id")
private Orders orders;//订单ID private Orders orders;//订单ID
} }

View File

@ -1,13 +1,11 @@
package com.example.springdemo.entities; package com.example.springdemo.entities;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor; import lombok.*;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -24,12 +22,11 @@ public class Orders {
private Long id;//订单ID private Long id;//订单ID
@OneToMany(cascade = CascadeType.ALL, mappedBy = "orders") @OneToMany(cascade = CascadeType.ALL, mappedBy = "orders")
@Column(name = "orderDishesID") private List<OrderDishes> orderDishes = new ArrayList<>();//订单中的菜品
private List<OrderDishes> orderDishes;//订单中的菜品
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) //多个订单对应一个用户关系是多对一订单创建后添加用户ID可以主动改变关系因此是主控方
@JoinColumn(name = "usersID", referencedColumnName = "id") @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Column(name = "usersID") @JoinTable()
private Users user;//外键下单用户 private Users user;//外键下单用户
@Column(name = "allPrice") @Column(name = "allPrice")

View File

@ -14,9 +14,11 @@ public class RolesPermissions {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;//主键 private Long id;//主键
@OneToMany(targetEntity = Roles.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(targetEntity = Roles.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Column(name = "RolesID") @Column(name = "RolesID")
private List<Roles> roles;//角色ID private List<Roles> roles;//角色ID
@OneToMany(targetEntity = Permissions.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(targetEntity = Permissions.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Column(name = "PermissionsID") @Column(name = "PermissionsID")
private List<Permissions> permissions;//权限ID private List<Permissions> permissions;//权限ID

View File

@ -7,6 +7,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List; import java.util.List;
//用户类 //用户类
@ -26,12 +27,12 @@ public class Users {
private String phoneNumber;//用户联系方式 private String phoneNumber;//用户联系方式
private String address;//家庭住址 private String address;//家庭住址
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user") //一个用户可能会有多个订单关系是一对多
@Column(name = "ordersID") @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Orders> orders;//订单 @JoinColumn(name = "id")
private List<Orders> orders = new ArrayList<>();//订单
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "rolesID", referencedColumnName = "id") @JoinColumn(name = "rolesID", referencedColumnName = "id")
@Column(name = "rolesID")
private Roles roles;//RBAC角色 private Roles roles;//RBAC角色
} }

View File

@ -12,8 +12,7 @@ import lombok.NoArgsConstructor;
public class MerchantsPassword { public class MerchantsPassword {
@Id @Id
@OneToOne @OneToOne
@Column(name = "merchantID") @PrimaryKeyJoinColumn(name = "merchantID", referencedColumnName = "id")
@JoinColumn(name = "merchantID", referencedColumnName = "id")
private Merchants merchants; private Merchants merchants;
private String password; private String password;
} }

View File

@ -12,8 +12,7 @@ import lombok.NoArgsConstructor;
public class UsersPassword { public class UsersPassword {
@Id @Id
@OneToOne @OneToOne
@Column(name = "userID") @PrimaryKeyJoinColumn(name = "userID", referencedColumnName = "id")
@JoinColumn(name = "userID", referencedColumnName = "id")
private Users users; private Users users;
private String password; private String password;
} }