当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Detailed explanation of DBPack SQL Tracing function and data encryption function
极化微波成像概述
QT_事件类
SQL的substring_index()用法——MySQL字符串截取
XAML WPF item groupBox control
【100个网络运维工作者必须知道的小知识!】
What is the implementation principle of Go iota keyword and enumeration type
opencv如何实现图像倾斜校正
OpenCV安装、QT、VS配置项目设置
面经汇总-社招-6年
opencv基本的图像处理
QLineEdit学习与使用
消息模板占位符的使用
理财产品的月年化收益率怎么算?
QT基础功能,信号、槽
EpiSci | Deep Reinforcement Learning for SoCs: Myth and Reality
暑假第一周总结博客
Go GORM事务实例分析
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
JVM运行时数据区与JMM内存模型是什么









