简体   繁体   English

Spring 启动延迟加载 OrderLine 项目上的订单 GetMapping 请求

[英]Spring Boot Lazy Loading OrderLine items on Orders GetMapping Request

I have the following getMapping request in OrderController for a simple E-Commerce Spring Boot application to demo MVC.我在 OrderController 中有以下 getMapping 请求,用于演示 MVC 的简单电子商务 Spring 引导应用程序。

@GetMapping("/all")
    public List<Orders> getAllOrders() {
        return ordersService.getAllOrders();
    }

In Postman, I get the response accordingly:在 Postman 中,我得到相应的响应:

[
    {
        "order_date": "2021-04-29T19:55:30.964+00:00",
        "amount": 33.0,
        "status": true,
        "id": 3
    },
...

I have a OrderDetailVO (Integer productId, Integer quantity) and OrderVO (orderID, ArrayList OrderDetailList) classes in my Models as well.我的模型中还有一个 OrderDetailVO(整数 productId,Integer 数量)和 OrderVO(orderID,ArrayList OrderDetailList)类。

I want to see the products associated with the Order in my get response.我想在我的获取响应中查看与订单相关的产品。 Is there a way to Return OrderVO object and OL object along with the Order object?有没有办法将订单VO object和OL object连同订单object一起退回?

Structure:结构: 项目结构

You can use Mapping annotation like @ManyToOne @OneToMany in your entity class to get orderDetails.您可以在您的实体 class 中使用像 @ManyToOne @OneToMany 这样的映射注释来获取 orderDetails。 Follow along below guide to understand mapping in spring boot:按照以下指南了解 spring 引导中的映射:

https://www.baeldung.com/hibernate-one-to-many https://www.baeldung.com/hibernate-one-to-many

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM