From fec941e6ca34ad8a344a07fba8aa8eb678d6f793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E5=AE=9B=E5=BD=A4?= <1484985080@qq.com> Date: Mon, 11 May 2026 11:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E8=BF=9Bproduct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/ssm/entity/Product.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java b/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java index 1a2cac2..6355990 100644 --- a/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java +++ b/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java @@ -114,4 +114,33 @@ public class Product { ", listDate='" + listDate + '\'' + '}'; } + + // 计算折扣率 + public Double getDiscountRate() { + if (marketPrice != null && marketPrice > 0 && salesPrice != null) { + return (salesPrice / marketPrice) * 10; + } + return 0.0; + } + + // 判断是否有优惠 + public boolean hasDiscount() { + if (marketPrice != null && salesPrice != null) { + return salesPrice < marketPrice; + } + return false; + } + + // 获取节省金额 + public Double getSavedAmount() { + if (marketPrice != null && salesPrice != null) { + return marketPrice - salesPrice; + } + return 0.0; + } + + // 判断是否为热门商品 + public boolean isHotProduct() { + return "是".equals(isPopular) || "true".equalsIgnoreCase(isPopular) || "1".equals(isPopular); + } }