From 5ce83e1a26bb5cfcd43eb56e6d9ebcd66b51166a Mon Sep 17 00:00:00 2001 From: CR7 <1965214192@qq.com> Date: Wed, 18 Dec 2024 21:39:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IndexImgServiceImpl.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 yami-shop-service/src/main/java/com/yami/shop/service/impl/IndexImgServiceImpl.java diff --git a/yami-shop-service/src/main/java/com/yami/shop/service/impl/IndexImgServiceImpl.java b/yami-shop-service/src/main/java/com/yami/shop/service/impl/IndexImgServiceImpl.java new file mode 100644 index 0000000..546c705 --- /dev/null +++ b/yami-shop-service/src/main/java/com/yami/shop/service/impl/IndexImgServiceImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ + +package com.yami.shop.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import com.yami.shop.bean.model.IndexImg; +import com.yami.shop.dao.IndexImgMapper; +import com.yami.shop.service.IndexImgService; + +import java.util.List; + +/** + * IndexImgServiceImpl 是IndexImgService接口的具体实现类。 + * 它继承自MyBatis-Plus提供的ServiceImpl,并实现了IndexImgService接口中定义的方法。 + * 该服务负责处理与首页图片(IndexImg)相关的业务逻辑。 + * + * @author lgh on 2018/11/26. + */ +@Service +public class IndexImgServiceImpl extends ServiceImpl implements IndexImgService { + + /** + * indexImgMapper是通过Spring自动装配的DAO层组件, + * 用于执行对IndexImg实体对应的数据库表的操作。 + */ + @Autowired + private IndexImgMapper indexImgMapper; + + /** + * deleteIndexImgByIds方法实现了根据给定ID列表批量删除首页图片的功能。 + * 它调用了indexImgMapper中的deleteIndexImgByIds方法来执行实际的删除操作。 + */ + @Override + public void deleteIndexImgByIds(Long[] ids) { + indexImgMapper.deleteIndexImgByIds(ids); + } + + /** + * listIndexImg方法返回所有首页图片的列表。 + * 使用了@Cacheable注解以启用Spring Cache缓存机制, + * 这样可以避免重复查询数据库,提高性能。 + * 当首次调用此方法时,结果会被缓存起来; + * 后续相同请求将直接从缓存中读取数据,直到缓存失效或被手动清除。 + */ + @Override + @Cacheable(cacheNames = "indexImg", key = "'indexImg'") + public List listIndexImg() { + return indexImgMapper.listIndexImg(); + } + + /** + * removeIndexImgCache方法用于清除首页图片的缓存。 + * 使用了@CacheEvict注解,当调用此方法时会清除指定名称的缓存, + * 确保在需要的时候缓存内容是最新的。 + */ + @Override + @CacheEvict(cacheNames = "indexImg", key = "'indexImg'") + public void removeIndexImgCache() { + // 方法体为空,因为实际的缓存清除工作由@CacheEvict注解完成。 + } +}