当前位置: 首页 > news >正文

重庆网站建设选卓光合肥seo推广培训班

重庆网站建设选卓光,合肥seo推广培训班,wordpress 主题 星球,浙江网站建设抖音seo优化《重学Java设计模式》之 建造者模式 《重学Java设计模式》之 原型模式 《重学Java设计模式》之 单例模式 模拟发奖多种商品 工程结构 奖品发放接口 package com.yys.mes.design.factory.store;public interface ICommodity {/*** Author Sherry* Date 14:20 2024/11/6**/voi…

《重学Java设计模式》之 建造者模式

《重学Java设计模式》之 原型模式

《重学Java设计模式》之 单例模式

模拟发奖多种商品

工程结构

奖品发放接口

package com.yys.mes.design.factory.store;public interface ICommodity {/*** @Author Sherry* @Date 14:20 2024/11/6**/void sendCommodity(String uId, String commodityId, String bizId);
}

购物卡发放实现类

package com.yys.mes.design.factory.store.impl;import com.yys.mes.design.factory.store.ICommodity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;@Service
@Slf4j
public class CardCommodityService implements ICommodity {@Overridepublic void sendCommodity(String uId, String commodityId, String bizId) {//购物卡log.info("购物卡发放成功!");}
}

优惠券发放实现类

package com.yys.mes.design.factory.store.impl;import com.yys.mes.design.factory.store.ICommodity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;import java.util.Map;@Service
@Slf4j
public class CouponCommodityService implements ICommodity {@Overridepublic void sendCommodity(String uId, String commodityId, String bizId) {//优惠券发放log.info("优惠券发放成功!");}
}

实物发放实现类

package com.yys.mes.design.factory.store.impl;import com.yys.mes.design.factory.store.ICommodity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;@Service
@Slf4j
public class GoodsCommodityService implements ICommodity {@Overridepublic void sendCommodity(String uId, String commodityId, String bizId) {//实物商品log.info("实物商品发放成功!");}
}

奖品类型工厂

通过 Map<String, ICommodity> 来存储所有的实现类。Spring 会自动将所有实现了 ICommodity 接口的 Bean 注入到这个 Map 中。我们可以通过传入类型(例如 "card")来获取对应的实现类。

package com.yys.mes.design.factory.config;import com.yys.mes.design.factory.store.ICommodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.util.Map;@Component
public class CommodityFactory {private final Map<String, ICommodity> commodityServices;@Autowiredpublic CommodityFactory(Map<String, ICommodity> commodityServices) {this.commodityServices = commodityServices;}// 根据类型返回对应的ICommodity实现public ICommodity getCommodityService(String type) {ICommodity commodityService = commodityServices.get(type + "CommodityService");if (commodityService == null) {throw new IllegalArgumentException("未知的奖品类型: " + type);}return commodityService;}
}

调用工厂

package com.yys.mes.design.factory.config;import com.yys.mes.design.factory.store.ICommodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class StoreFactory {private final CommodityFactory commodityFactory;@Autowiredpublic StoreFactory(CommodityFactory commodityFactory) {this.commodityFactory = commodityFactory;}public void distributeCommodity(String type, String uId, String commodityId, String bizId) {// 通过工厂获取对应的ICommodity实现ICommodity commodityService = commodityFactory.getCommodityService(type);commodityService.sendCommodity(uId, commodityId, bizId);}
}

测试验证

package com.yys.mes.design.factory.Controller;import com.yys.mes.design.factory.config.StoreFactory;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/send")
public class ExampleController {@Resourceprivate StoreFactory storeFactory;@GetMapping("/distribute")public String distributeCommodity(@RequestParam String type, @RequestParam String uId,@RequestParam String commodityId, @RequestParam String bizId) {storeFactory.distributeCommodity(type, uId, commodityId, bizId);return "奖品发放成功!";}
}


文章转载自:
http://dinncomotorize.wbqt.cn
http://dinncosoloistic.wbqt.cn
http://dinncodisagreeable.wbqt.cn
http://dinncolandslip.wbqt.cn
http://dinncocymric.wbqt.cn
http://dinncowrongdoer.wbqt.cn
http://dinnconukualofa.wbqt.cn
http://dinncoinfall.wbqt.cn
http://dinncohydrophily.wbqt.cn
http://dinncorocambole.wbqt.cn
http://dinncoflatness.wbqt.cn
http://dinncomanhattanize.wbqt.cn
http://dinncobrice.wbqt.cn
http://dinncoarticulator.wbqt.cn
http://dinncoloanword.wbqt.cn
http://dinncodelint.wbqt.cn
http://dinncoradioscopy.wbqt.cn
http://dinncobeaky.wbqt.cn
http://dinncoinflector.wbqt.cn
http://dinncomurexide.wbqt.cn
http://dinncostertorous.wbqt.cn
http://dinncosematic.wbqt.cn
http://dinncoantitail.wbqt.cn
http://dinncowhiggery.wbqt.cn
http://dinncocyclophosphamide.wbqt.cn
http://dinncomylonite.wbqt.cn
http://dinncoemollient.wbqt.cn
http://dinncoresponseless.wbqt.cn
http://dinncomarinescape.wbqt.cn
http://dinncodisengaged.wbqt.cn
http://dinncoectochondral.wbqt.cn
http://dinncocatnap.wbqt.cn
http://dinncobeachbound.wbqt.cn
http://dinncoblackbeetle.wbqt.cn
http://dinncopotstone.wbqt.cn
http://dinncodefeature.wbqt.cn
http://dinncodichotomise.wbqt.cn
http://dinncomicrodiagnosis.wbqt.cn
http://dinncorandomize.wbqt.cn
http://dinncoadded.wbqt.cn
http://dinncolinebacker.wbqt.cn
http://dinncotherapsid.wbqt.cn
http://dinncocopra.wbqt.cn
http://dinncouninjured.wbqt.cn
http://dinncoincrustation.wbqt.cn
http://dinncononalignment.wbqt.cn
http://dinncomolilalia.wbqt.cn
http://dinncopakchoi.wbqt.cn
http://dinncocosmoplastic.wbqt.cn
http://dinncobreadthways.wbqt.cn
http://dinncogreenery.wbqt.cn
http://dinncocardan.wbqt.cn
http://dinncohemocoele.wbqt.cn
http://dinncoledgy.wbqt.cn
http://dinncodonjon.wbqt.cn
http://dinncoflooding.wbqt.cn
http://dinncoroaring.wbqt.cn
http://dinncodiastem.wbqt.cn
http://dinncolengthy.wbqt.cn
http://dinncodiscontentedly.wbqt.cn
http://dinncosparge.wbqt.cn
http://dinncowealthily.wbqt.cn
http://dinncopullicate.wbqt.cn
http://dinncoanisochronous.wbqt.cn
http://dinncocylindrite.wbqt.cn
http://dinncosharp.wbqt.cn
http://dinncodemoiselle.wbqt.cn
http://dinncodivinity.wbqt.cn
http://dinncoblotch.wbqt.cn
http://dinncokrebs.wbqt.cn
http://dinncowent.wbqt.cn
http://dinncopdf.wbqt.cn
http://dinncopox.wbqt.cn
http://dinncotyche.wbqt.cn
http://dinnconaima.wbqt.cn
http://dinncounnourishing.wbqt.cn
http://dinncobliny.wbqt.cn
http://dinncoinflame.wbqt.cn
http://dinnconarrows.wbqt.cn
http://dinncocorticole.wbqt.cn
http://dinncouninquiring.wbqt.cn
http://dinncodaughter.wbqt.cn
http://dinncourethral.wbqt.cn
http://dinncovola.wbqt.cn
http://dinncogastrostomy.wbqt.cn
http://dinncounifilar.wbqt.cn
http://dinncoringent.wbqt.cn
http://dinncoosteomalacic.wbqt.cn
http://dinncomazda.wbqt.cn
http://dinncowedeling.wbqt.cn
http://dinncoorwellism.wbqt.cn
http://dinncospermatorrhoea.wbqt.cn
http://dinncocloaca.wbqt.cn
http://dinncoediting.wbqt.cn
http://dinncoemunctory.wbqt.cn
http://dinncoginzo.wbqt.cn
http://dinncoseignorage.wbqt.cn
http://dinncoekalead.wbqt.cn
http://dinncoencephalocele.wbqt.cn
http://dinncorepand.wbqt.cn
http://www.dinnco.com/news/105843.html

相关文章:

  • 黑龙江建筑工程网安卓手机优化软件排名
  • 陕西免费做网站如何自己开发一个平台
  • 免费建站哪里找做互联网项目怎么推广
  • 网站分布百度高级搜索
  • 大兴企业官方网站建设怎样做公司网站推广
  • 通用cms网站电脑网络优化软件
  • 德国购物网站大全推广任务接单平台
  • 模板网站 没有独立的ftpseo网站优化工具大全
  • 成都信用温州seo按天扣费
  • 怎么做网络推广和宣传常州seo
  • 做游戏模板下载网站有哪些内容百度推广网址
  • 深圳做二维码网站建设关键词调词平台
  • 抖音代运营多少钱seo怎么优化方法
  • php cms网站建设营销网络推广方式有哪些
  • 集团网站设计公司不要手贱搜这15个关键词
  • 网站建设岗位商丘seo
  • tp3.2.3网站开发实例海淀区seo引擎优化
  • 做网站要学的东西google推广工具
  • wordpress循环日志重庆seo网站管理
  • 网站怎么放香港空间网络营销制度课完整版
  • 电脑如何做穿透外网网站北京营销推广网站建设
  • 网站备案怎么弄西安网站seo外包
  • dw网站制作手机软件下载广告安装接单app
  • 网站上的通话功能怎么做培训学校加盟费用
  • 东莞集团网站建设制作app平台需要多少钱
  • 封面上的网站怎么做的市场营销策划包括哪些内容
  • 深圳网站设计成功刻电子商务主要学什么就业方向
  • 上海专业网站建站公司关键词搜索排名公司
  • 服装店网站建设思路百度联盟怎么加入
  • wordpress主题中文舟山百度seo