当前位置:网站首页>Use of message template placeholders
Use of message template placeholders
2022-08-01 18:11:00 【Mianzhi~】
Use of message template placeholders
一 具体实现
说明:根据@Placeholders go in to match placeholders
案例:“模板名称:@[email protected],发生了变更,变更描述:@[email protected] description of the change is:@[email protected]”;
1. 占位符解析
//Parse the placeholder concatenated message template
public String getContent(MsgType msgType, Map<String, String> messageAttrMap) {
//Get a message template with placeholders
String result = messageTypeRepo.getByCode(msgType.name()).getContentTemplate();
//result = "模板名称:@[email protected],发生了变更,变更描述:@[email protected] description of the change is:@[email protected]";
Pattern pattern = Pattern.compile("@(.*?)@");
Matcher matcher = pattern.matcher(result);
while (matcher.find()) {
//占位符
String placeholder = matcher.group();
String key = placeholder.substring(1, placeholder.length() - 1);
if (messageAttrMap.containsKey(key)) {
String value = "null";
if (Objects.nonNull(messageAttrMap.get(key))) {
value = messageAttrMap.get(key).trim();
}
result = StringUtils.replaceAll(result, placeholder, value);
// System.out.println(result);
}
}
return result;
}
2. Assignment of placeholder parameters
@ApiModelProperty(value = "消息模板类型",required = true)
private MsgType msgType;
@ApiModelProperty(value = "Properties of the message content",required = true)
private Map<String, String> msgAttrMap;//keyThere may be duplicate attribute fields,需要替换,valueis the value of the replaced field,Placeholder for message templates
边栏推荐
猜你喜欢
随机推荐
SQL的substring_index()用法——MySQL字符串截取
如何让固定点的监控设备在EasyCVR平台GIS电子地图上显示地理位置?
金鱼哥RHCA回忆录:CL210管理OPENSTACK网络--章节实验
【Day_08 0426】两种排序方法
B011 - 基于51的多功能指纹智能锁
SQL的索引详细介绍
Tower Defense Shoreline User Agreement
我在启牛开户安全吗?谁能告诉我开不靠谱?
How to make the fixed-point monitoring equipment display the geographic location on the EasyCVR platform GIS electronic map?
生物制药产业发展现状和趋势展望
SQL窗口函数
公用函数----mfc
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) Solution
SQL函数 TO_DATE(二)
【Day_10 0428】密码强度等级
tooltip control
Go GORM transaction instance analysis
阿里云的域名和ip绑定
Leetcode71. Simplified Paths
ExcelPatternTool: Excel表格-数据库互导工具









