当前位置:网站首页>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
边栏推荐
- Binary sort tree (BST)~
- 高效,可靠,安全的串口通讯开源方案
- Redis persistence RDB
- 5-year-old Test Engineer - how to choose the next step?
- ERROR: Could not open requirements file: [Errno 2] No such file or directory: ‘requirments.txt’
- 《MongoDB入门教程》第08篇 比较运算符
- Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
- Hack The Box - Introduction to Networking Module详细讲解中文教程
- leetcode-Array
- I also found excellent software and hardware projects, all open source
猜你喜欢

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

SSTI payload and various bypass methods

MBA-day28 数的概念-练习题
![[STM32 series summary] blogger's way to quickly advance STM32 in actual combat (continuous update)](/img/20/bf7d2653aafd35e6588f819d110453.png)
[STM32 series summary] blogger's way to quickly advance STM32 in actual combat (continuous update)

Knowledge points of Polymer Physics

Embedded general learning route arrangement

Yolov3 preparatory work

高频电子线路复习考试题及答案

Development projects get twice the result with half the effort, a large collection of open source STM32 driver Libraries

这种项目,最好别接!
随机推荐
Dynamic memory management and flexible array
Benji Banas launched the second season of earn while playing bonus activities, supporting the use of multiple Benji passes!
DOM operation -- operation node
日志收集分析平台搭建-1-环境准备
sdc中对cdc的处理方式
Yolov3 preparatory work
Use latex to typeset multiple-choice test paper
Polymer physics test question bank
Kingbasees SQL language reference manual of Jincang database (9. Common DDL clauses)
Rocbossphp free open source light community system
How are masters refined?
Nn.moudle module - details of creating neural network structure
Two auxiliary functions of integral Mall for business user operation
三本毕业,三年嵌入式软件的心路历程
数仓搭建-DIM层
Select sort / insert sort / bubble sort
这种项目,最好别接!
Embedded general learning route arrangement
芯片的翻新和造假,人被坑麻了
Application of canoe XML in test modules