简体   繁体   English

如何在 Spring Boot 中获取添加订单的选定项目?

[英]How can I get the selected items for adding an order in Spring Boot?

I have three entities user, item, order.我有三个实体用户,项目,订单。 ORDER entity has ManyToMany association with item and ManyToOne with user. ORDER 实体与项目具有多对多关联,与用户具有多对一关联。

1.Item Entity 1.物品实体

@Entity
public class Item {
Integer id;
String name;
String category;

@ManyToMany
Order order;

}

2.User Entity 2.用户实体

@Entity
public class user {
Integer id;
String username;
String email;

@OneToMany
Order order;

}

3.order Entity 3.订单实体

@Entity
public class order {
Integer id;
Integer price;
Integer quantity;
String address;
Integer p_number;

@ManyToOne
Use user;

@ManyToMany
Item item;

}

I've problem with adding an order, I don't know how to get selected items in orderService class for addOrder method?我在添加订单时遇到问题,我不知道如何在 addOrder 方法的orderService class 中获取所选项目?

OrderServiceImpl.java OrderServiceImpl.java

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderRepo orderRepo;

    public Order addOrder (Order order) {
        return orderRepo.save(order);
    }

}

In mapping, the fields representing many side have to be either list or set在映射中,表示多面的字段必须是列表或集合

In user entity在用户实体中

@OneToMany(mappedBy="user")
List<Order> orders;

In item entity在项目实体中

@ManyToMany
List<Order> orders;

In order entity在订单实体

@ManyToOne
Use user;

@ManyToMany
List<Item> items;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Spring 启动中的获取映射请求中发送一个字符串列表作为参数,其中包含很多项目? - How can I send a String list as param with a lot of items in a get mapping request in Spring boot? 如何从JComboBox中的选定项目中获取包含2个项目的数组? - How I can get an array with 2 items from a selected item in a JComboBox? 如何在listdialog的click事件中获取选定的项目? - How can I get selected items on listdialog's click event? 如何在 FilterRegistrationBean 中获取 @PathVariable? 弹簧靴 - How can I get @PathVariable inside FilterRegistrationBean? Spring Boot 我如何获得在 spring boot 中具有角色的所有用户的列表? - How can i get the liste of all users with roles in spring boot? 如何在Spring Boot中通过检查嵌套对象来获取对象? - How can i get an object with checks on nested object in Spring boot? 如何在 Spring Boot 中获取请求的客户端 IP 地址? - How can I get the client IP address of requests in Spring Boot? 如何以正确的形式获取信息(Spring Boot) - How can I get the information in the correct form (Spring Boot) 如何在Spring-Boot中获取属性文件的bean? - How can I get the bean of a property file in Spring-Boot? 如何从线程将项目添加到列表并保持添加顺序? - How can I add items to a list from a thread and keep the adding order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM