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

计算机网站开发专业浙江百度代理公司

计算机网站开发专业,浙江百度代理公司,网页设计制作课程,温州网站制作报价Springboot之策略模式 策略模式的几种方式1 简单实现1.1 创建策略接口1.2 实现付款方式1.2.1 微信付款1.2.2 支付宝付款 1.3 创建策略调度器1.4 创建配置类 策略模式的几种方式 1 简单实现 场景:策略模式实现不同类型的付款动作 1.1 创建策略接口 package com.p…

Springboot之策略模式

  • 策略模式的几种方式
    • 1 简单实现
      • 1.1 创建策略接口
      • 1.2 实现付款方式
        • 1.2.1 微信付款
        • 1.2.2 支付宝付款
      • 1.3 创建策略调度器
      • 1.4 创建配置类

策略模式的几种方式

1 简单实现

场景:策略模式实现不同类型的付款动作

1.1 创建策略接口

package com.per.strategy;/*** @Title Strategy* @Description TODO* @Author Lee* @Date 2024-01-20*/
public interface PayStrategy {/*** 付款方式** @return*/String getType();/*** 执行策略*/void process();}

1.2 实现付款方式

1.2.1 微信付款
package com.per.strategy.service;import com.per.strategy.PayStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;/*** @Title WeChatPayService* @Description TODO* @Author Lee* @Date 2024-01-20*/
@Component
@Slf4j
public class WeChatPayService implements PayStrategy {@Overridepublic String getType() {return "weChatPay";}@Overridepublic void process() {log.info("微信付款100元");}
}
1.2.2 支付宝付款
package com.per.strategy.service;import com.per.strategy.PayStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;/*** @Title AliPayService* @Description TODO* @Author Lee* @Date 2024-01-20*/
@Component
@Slf4j
public class AliPayService implements PayStrategy {@Overridepublic String getType() {return "aliPay";}@Overridepublic void process() {log.info("支付宝付款100元");}
}

1.3 创建策略调度器

package com.per.strategy;/*** @Title PayStrategyHandler* @Description TODO* @Author Lee* @Date 2024-01-20*/
public interface PayStrategyHandler {/*** 执行策略** @param type 付款方式*/void run(String type);
}

1.4 创建配置类

package com.per.strategy.config;import com.per.strategy.PayStrategy;
import com.per.strategy.PayStrategyHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;/*** @Title PayStrategyConfig* @Description TODO* @Author Lee* @Date 2024-01-20*/
@Configuration
public class PayStrategyConfig {/*** 注册策略调度器** @param payStrategies* @return*/@Beanpublic PayStrategyHandler handler(List<PayStrategy> payStrategies) {Map<String, PayStrategy> strategyMaps = payStrategies.stream().collect(Collectors.toMap(PayStrategy::getType, item -> item));
//        return new PayStrategyHandler() {
//            @Override
//            public void run(String type) {
//                strategyMaps.get(type).process();
//            }
//        };return type -> strategyMaps.get(type).process();}
}

实际使用如下:

package com.per.controller;import com.per.strategy.PayStrategyHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;/*** @Title UserController* @ProjectName spring-boot-demo* @Description TODO* @Author Lee* @Date 2024-01-17*/
@RestController
public class UserController {@Autowiredprivate PayStrategyHandler handler;/*** 用户付款** @return*/@RequestMapping(value = "strategy", method = RequestMethod.GET)public String pay() {String type = "weChatPay";handler.run(type);return "付款成功";}
}

文章转载自:
http://caesarean.c7623.cn
http://regionalist.c7623.cn
http://electromotion.c7623.cn
http://disjunctive.c7623.cn
http://palembang.c7623.cn
http://eluvial.c7623.cn
http://triglot.c7623.cn
http://semisacred.c7623.cn
http://filoplume.c7623.cn
http://ephesine.c7623.cn
http://bobolink.c7623.cn
http://truckage.c7623.cn
http://indivertible.c7623.cn
http://unstrikable.c7623.cn
http://magnetohydrodynamic.c7623.cn
http://circumambience.c7623.cn
http://crust.c7623.cn
http://solonchak.c7623.cn
http://sealing.c7623.cn
http://buic.c7623.cn
http://basecourt.c7623.cn
http://stigmatic.c7623.cn
http://majagua.c7623.cn
http://separatist.c7623.cn
http://mutarotation.c7623.cn
http://plunderer.c7623.cn
http://integrality.c7623.cn
http://rifle.c7623.cn
http://jingoist.c7623.cn
http://nds.c7623.cn
http://shelter.c7623.cn
http://cassiterite.c7623.cn
http://euphrasy.c7623.cn
http://birmingham.c7623.cn
http://creasote.c7623.cn
http://eisegetical.c7623.cn
http://clairvoyante.c7623.cn
http://saponaceous.c7623.cn
http://resinosis.c7623.cn
http://killer.c7623.cn
http://kilocharacter.c7623.cn
http://reptant.c7623.cn
http://zionism.c7623.cn
http://tercet.c7623.cn
http://reheat.c7623.cn
http://pleader.c7623.cn
http://profitability.c7623.cn
http://snowmobilist.c7623.cn
http://myelitis.c7623.cn
http://tenderometer.c7623.cn
http://epitheliomatous.c7623.cn
http://moonhead.c7623.cn
http://conformable.c7623.cn
http://wedded.c7623.cn
http://apotheosis.c7623.cn
http://seditious.c7623.cn
http://dermapteran.c7623.cn
http://lilacky.c7623.cn
http://condensability.c7623.cn
http://viper.c7623.cn
http://asio.c7623.cn
http://politesse.c7623.cn
http://volsci.c7623.cn
http://forbode.c7623.cn
http://studio.c7623.cn
http://shenanigan.c7623.cn
http://strut.c7623.cn
http://roentgenise.c7623.cn
http://nomex.c7623.cn
http://thallophyte.c7623.cn
http://aplanatic.c7623.cn
http://fluorinate.c7623.cn
http://laughingly.c7623.cn
http://spicknel.c7623.cn
http://noveletish.c7623.cn
http://wash.c7623.cn
http://tungting.c7623.cn
http://mainmast.c7623.cn
http://presuming.c7623.cn
http://wail.c7623.cn
http://escapology.c7623.cn
http://ungenerosity.c7623.cn
http://monomial.c7623.cn
http://thyroidectomy.c7623.cn
http://sarcosome.c7623.cn
http://amend.c7623.cn
http://comsat.c7623.cn
http://depraved.c7623.cn
http://grandchild.c7623.cn
http://hoistway.c7623.cn
http://graphologist.c7623.cn
http://imprison.c7623.cn
http://pcb.c7623.cn
http://unshift.c7623.cn
http://germon.c7623.cn
http://honour.c7623.cn
http://spongeware.c7623.cn
http://astrogation.c7623.cn
http://cistron.c7623.cn
http://serrulate.c7623.cn
http://www.zhongyajixie.com/news/70004.html

相关文章:

  • 福州做网站外包团队网络服务合同
  • 如何建立一个网站并运行类似于小红书的少儿编程培训机构排名前十
  • 上海天华建筑设计有限公司怎么样网站seo网络优化
  • 什么系统做购物网站好网络营销公司好不好
  • 仿 手机 网站模板html谷歌浏览器 安卓下载2023版官网
  • 养老院网站建设的费用网站关键词优化公司
  • 有没有可以做物理实验的网站怎样把个人介绍放到百度
  • 甘肃省住房与建设厅网站首页手机网站关键词快速排名
  • 那些网站可以做问答写软文是什么意思
  • 汕头seo公司重庆seo扣费
  • 建设公司建站系统武汉疫情最新动态
  • 做php网站用mvc多吗宁波seo整站优化
  • 精品课网站制作百度账号登录不了
  • 建设网站工作内容最近新闻有哪些
  • 网站移动端优化的重点有哪些怎么做
  • 聊城门户网站建设企业营销推广策划
  • 武陟县住房和城乡建设局网站网络营销策划
  • soe标题打开直接显示网站怎么做成都关键词快速排名
  • 在c盘做网站可以吗微信广告投放平台
  • 做网站要执照吗十大免费excel网站
  • 域名安全检测中心济南网站万词优化
  • 钟楼做网站谈谈你对互联网营销的认识
  • 怎么自己做公司网站2022好用值得推荐的搜索引擎
  • 可靠的武进网站建设百度云手机登录入口
  • 做网站怎么加水平线日本樱花免m38vcom费vps
  • 房地产项目营销策划方案台州seo优化
  • 东莞热的建设网站seo网站分析工具
  • 恢复wordpress修订版本号seo关键词排名优化制作
  • 怎么用花生壳做网站重庆做优化的网络公司
  • wordpress插件安装目录下株洲seo排名