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

上饶市住房城乡建设局网站wordpress固定字段

上饶市住房城乡建设局网站,wordpress固定字段,百合网网站建设与策划,网站模板凡平台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/293378/

相关文章:

  • 网站报价单网站模版怎么修改
  • 外贸网站运营是做什么的咨询公司网站建设
  • 网站备案信息保护湖南省郴州市天气
  • 专业建站工作室开源cms框架
  • 青岛制作企业网站的公司wordpress 图片模板修改
  • 拱墅区建设局网站.网站开发工具dw
  • php网站运行很慢无锡网站建设要多少钱
  • 建设个人网站第一步这么做均安网站建设
  • 查看网站开通时间网站开发费用属无形资产吗
  • 网站开发的后期维护怎么做购物网站到
  • wp做音乐网站必备公司建网站怎么弄
  • 新乡专业网站制作建设银行网站为什么进不去
  • 制作一个链接网站怎么做网页二维码
  • 网站搭建与生成技术教材仿煎蛋 wordpress
  • 湛江做网站苏州厂商微信上微网站怎么做的
  • 苏州网站建设专业的公司求个网站
  • 网站建设质量保证金定远县建设局网站
  • 樟木头镇网站建设公司惠州seo关键词推广
  • asp婚纱摄影网站公司建立网站青岛电话
  • 网站制作网站优化手机网址2021年免费不封
  • 中文字体怎么设计网站wordpress标签代码
  • 网站开发 前端vue 后端c简单的管理系统有哪些
  • 信用渭南网站建设专业做公司网站
  • 附近培训电脑的地方重庆seo整站优化效果
  • 蚌埠网站关键词优化一个虚拟主机能安装2个网站吗
  • 资源网站源码怎样做淘宝联盟网站
  • 电子 网站建设申请过程制作网站协议书
  • 设计一个网站重点是什么dw软件怎么下载
  • 山西城乡和住房建设厅网站首页网页制作素材末班
  • 濮阳网站优化公司哪家好wordpress linux 下载