当前位置:网站首页>Realize channel routing based on policy mode
Realize channel routing based on policy mode
2022-07-26 05:47:00 【Road Travel Asia】
First, adopt the channel information that needs to be routed map encapsulate , In this case , You can route based on specific policies when using .
@Component
public class PayContextStrategy {
private static final String aliPay ="10001";
private static final String yinlian ="10002";
// Containers : map
private static Map<String, PayStrategy> strategyMap = new ConcurrentHashMap<>();
// A static block : static
static {
strategyMap.put(aliPay, new AliPayStrategy());
strategyMap.put(yinlian, new YinLianPayStrategy());
}
// Get instance object
public static PayStrategy getInstance(String code) {
return strategyMap.get(code);
}
public String toPay(String payCode){
PayStrategy payStrategy = getInstance(payCode);
if(payStrategy==null){
return " No information of this channel ";
}
return payStrategy.toPay();
}
}Optimize : Channel information can be placed in enumeration , Then put it into the map in .
Alipay channel services :
@Component
public class AliPayStrategy implements PayStrategy {
public String toPay() {
return " Call Alipay payment interface ...";
}
}UnionPay channel payment service :
/**
* UnionPay payment
*/
@Component
public class YinLianPayStrategy implements PayStrategy {
public String toPay() {
return " Call UnionPay payment interface ...";
}
}To call :
@RestController
public class PayController {
@Autowired
private PayContextStrategy payContextStrategy;
@RequestMapping("/toPay")
public String toPay(String payCode){
if(StringUtils.isEmpty(payCode)){
return " channel code Can't be empty !";
}
return payContextStrategy.toPay(payCode);
}
}Of course, when invoking specific businesses , Policy call placed on service In business
边栏推荐
- Qt编写物联网管理平台47-通用数据库设置
- No EGL display error resolution
- 日志收集分析平台搭建-1-环境准备
- ETCD数据库源码分析——Cluster membership changes日志
- Redis transaction
- Autumn move - Preparation Plan
- Kingbasees SQL language reference manual of Jincang database (9. Common DDL clauses)
- Three graduates, three years of experience in embedded software
- The refurbishment and counterfeiting of chips have made people feel numb
- leetcode-aboutString
猜你喜欢

leetcode-aboutString

DOM operation -- operation node

Interview questions for software testing is a collection of interview questions for senior test engineers, which is exclusive to the whole network

vagrant下载速度慢的解决方法

Lamp architecture

Jdbc流式查询与游标查询

Attack and defense world -- easy_ web

Knowledge points of Polymer Physics

又一开源神器,值得收藏学习!

How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
随机推荐
高频电子线路复习考试题及答案
Project topic selection reference
满二叉树 / 真二叉树 / 完全二叉树 ~
ETCD数据库源码分析——Cluster membership changes日志
Select sort / insert sort / bubble sort
vagrant下载速度慢的解决方法
Redis 官方可视化工具,高颜值,功能真心强大!
三本毕业,三年嵌入式软件的心路历程
Lightweight MCU command line interaction project, all open source
解决Vagrant报错b:48:in `join‘: incompatible character encodings: GBK and UTF-8 (Encoding::Compatib
517. Super washing machine
Jdbc流式查询与游标查询
软件测试面试题全网独家没有之一的资深测试工程师面试题集锦
Solve vagrant's error b:48:in `join ': incompatible character encodings: GBK and UTF-8 (encoding:: Compatib
高分子物理试题库
C language explanation series -- understanding of functions (3) formal parameters, arguments, nested calls and chain access
Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
Redis主从复制
Benji Banas launched the second season of earn while playing bonus activities, supporting the use of multiple Benji passes!
金仓数据库 KingbaseES SQL 语言参考手册 (9. 常见DDL子句)