当前位置:网站首页>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
边栏推荐
猜你喜欢
B011 - 基于51的多功能指纹智能锁
【Error】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat’)
OpenCV installation, QT, VS configuration project settings
QPalette palette, frame color fill
2022年SQL大厂高频实战面试题(详细解析)
Leetcode72. 编辑距离
MySQL 45 Talk | 09 How to choose common index and unique index?
Shell nl命令详解(显示行号、读取文件)
Zabbix6.0钉钉机器人告警
面经汇总-社招-6年
随机推荐
Leetcode73. Matrix Zeroing
加州大学|通过图抽象从不同的第三人称视频中进行逆强化学习
JVM运行时数据区与JMM内存模型是什么
Shell nl命令详解(显示行号、读取文件)
EpiSci | Deep Reinforcement Learning for SoCs: Myth and Reality
2022年SQL经典面试题总结(带解析)
理财产品的月年化收益率怎么算?
2022年SQL大厂高频实战面试题(详细解析)
What is the JVM runtime data area and the JMM memory model
ExcelPatternTool: Excel表格-数据库互导工具
2022年MySQL最新面试题
WinRAR | 将多个安装程序生成一个安装程序
QT_QDialog 对话框
顺序表的简单描述及代码的简单实现
XAML WPF项目groupBox控件
Detailed explanation of DBPack SQL Tracing function and data encryption function
Leetcode72. Edit Distance
el-form-item prop属性动态绑定不生效如何解决
How to solve the dynamic binding of el-form-item prop attribute does not take effect
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近