简体   繁体   中英

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.

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

In Postman, I get the response accordingly:

[
    {
        "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.

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?

Structure: 项目结构

You can use Mapping annotation like @ManyToOne @OneToMany in your entity class to get orderDetails. Follow along below guide to understand mapping in spring boot:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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