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?
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:
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.