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

建设网站都需要准备什么材料各种网站末班

建设网站都需要准备什么材料,各种网站末班,定制研发服务,如何用VS2017做网站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://www.yayakq.cn/news/702885/

相关文章:

  • 编程自己做网站手机wordpress建站教程
  • 国内跨境电商网站给公司创建网站
  • 做公司网站多少钱深圳网站优化课程哪里学
  • 网站建设的成果怎么写网站开发的英文文献
  • 现在网站做多宽ui一般用什么软件做
  • 泗阳网站定制建设视频网站需要什么知识
  • 建设一个视频网站需要多少钱wordpress+重复插件
  • 网站托管服务合同范本华艺网络网站开发
  • 代码优化网站排名seo企业优化顾问
  • 贵州省住房建设部网站互联网推广引流是做什么的
  • 安徽网站建设论坛网页设计工资统计
  • 南通电商网站建设网站搭建教程视频
  • 网站开发 放大图片app开发科技网站建设
  • 建设网站需要展示什么有哪些专业做饰品的网站app
  • 网站logo设计教程东莞大岭山镇
  • 前端网站做完 后端用什么做如何给网站做引流
  • 用jsp做网站主界面导购分享网站模板
  • 做网站办贷款网站建设工作量评估
  • 杭州的网站建设公司有哪些国内免费建站平台
  • 培训网站系统建设wordpress广告最后加载
  • 微信软件wordpress速度优化存
  • 免费手机做网站电脑网页打不开是怎么回事
  • 电子商务网站建设说课稿成都甲壳虫品牌设计公司
  • 奖励软件下载网站dw做网站首页怎么做
  • 天津模板做网站网站设计网站建设专业
  • 创建个人网站名字网站建设的目的与意义是什么
  • 建立网站项目计划书模板推广方案100个
  • 资源分享网站怎么建设wordpress购物商城代码
  • silverlight 做的网站赣州章贡区旅游景点
  • 建设官方网站多少医疗网站建设 中企动力