'I am trying to make an API using spring boot and MongoDB. How should my entity class be for following template
I am trying to make an API using spring boot and MongoDB. How should my entity class be for following template I'm trying to have data in this format
{
"cart_id":"string",
"customer_name":"string"
"total_value":"double",
"line_items":
{
"product_name":"string",
"quantity":"number",
"price":"double"
}
}
Solution 1:[1]
Create an entity class like
@Data // lombok
@Document(collection="cart") //cart is your collection name
public class Cart {
@Id
private String id;
private String custname;
private double totval;
private LineItems line_items;
}
Create another class LineItems
@Data
public class LineItems {
private String prodname;
private int quant;
private int price;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shivam Kumar |
