package com.example.curd_example.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "OrderDetails")
public class OrderDetails implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "Order_detail_id", referencedColumnName = "id")
private ItemDetails itemDetails;
private int quantity;
private double price;
private double discountedAmount;
private double discountPercent;
@JsonProperty("isCouponApplied")
private boolean **isCouponApplied**;
private double discountedAmountForCoupon;
private double totalSavings;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ItemDetails getItemDetails() {
return itemDetails;
}
public void setItemDetails(ItemDetails itemDetails) {
this.itemDetails = itemDetails;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getDiscountedAmount() {
return discountedAmount;
}
public void setDiscountedAmount(double discountedAmount) {
this.discountedAmount = discountedAmount;
}
public double getDiscountPercent() {
return discountPercent;
}
public void setDiscountPercent(double discountPercent) {
this.discountPercent = discountPercent;
}
public boolean isCouponApplied() {
return isCouponApplied;
}
public void setCouponApplied(boolean isCouponApplied) {
this.isCouponApplied = isCouponApplied;
}
public double getDiscountedAmountForCoupon() {
return discountedAmountForCoupon;
}
public void setDiscountedAmountForCoupon(double discountedAmountForCoupon) {
this.discountedAmountForCoupon = discountedAmountForCoupon;
}
public double getTotalSavings() {
return totalSavings;
}
public void setTotalSavings(double totalSavings) {
this.totalSavings = totalSavings;
}
public OrderDetails(Long id, String name, ItemDetails itemDetails, int quantity, double price,
double discountedAmount, double discountPercent, boolean isCouponApplied, double discountedAmountForCoupon,
double totalSavings) {
super();
this.id = id;
this.name = name;
this.itemDetails = itemDetails;
this.quantity = quantity;
this.price = price;
this.discountedAmount = discountedAmount;
this.discountPercent = discountPercent;
this.isCouponApplied = isCouponApplied;
this.discountedAmountForCoupon = discountedAmountForCoupon;
this.totalSavings = totalSavings;
}
@Override
public String toString() {
return "OrderDetails [id=" + id + ", name=" + name + ", itemDetails=" + itemDetails + ", quantity=" + quantity
+ ", price=" + price + ", discountedAmount=" + discountedAmount + ", discountPercent=" + discountPercent
+ ", isCouponApplied=" + isCouponApplied + ", discountedAmountForCoupon=" + discountedAmountForCoupon
+ ", totalSavings=" + totalSavings + "]";
}
public OrderDetails() {
super();
}
}
Request:
{
“quantity”: 2,
“discountedAmountForCoupon”: 10,
“totalSavings”: 20
}
Here I didn’t passed isCouponApplied. But while mapping to POJO it set to its default value as false. So, in db also it was override the value true as false.
In spring boot CURD operation how can i do comparison for boolean vale and then update the value in DB.
if i passed the value then only it will update or else it won’t update the value how can i achieve this?