当前位置:网站首页>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
边栏推荐
- QT_QThread thread
- 暑假第一周总结博客
- SQL的substring_index()用法——MySQL字符串截取
- How to solve the dynamic binding of el-form-item prop attribute does not take effect
- Stop using MySQL online DDL
- Zabbix6.0钉钉机器人告警
- 以消费场景为驱动的CMDB要怎么建?
- 顺序表的简单描述及代码的简单实现
- What is the implementation principle of Go iota keyword and enumeration type
- 三种方案解决:npm WARN config global --global, --local are deprecated. Use --location=global instead.
猜你喜欢
随机推荐
md5sum源码 可多平台编译
Leetcode73. Matrix Zeroing
Leetcode73. 矩阵置零
How to make the fixed-point monitoring equipment display the geographic location on the EasyCVR platform GIS electronic map?
golang json 返回空值
ACID Characteristics and Implementation Methods of MySQL Relational Database Transactions
GRUB2的零日漏洞补丁现已推出
How opencv implements image skew correction
【报错】Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘concat‘)
SQL窗口函数
Go GORM transaction instance analysis
【Day_08 0426】两种排序方法
力扣每日一题-第45天-697. 数组的度
QT commonly used global macro definitions
阿里云的域名和ip绑定
Leetcode74. Search 2D Matrix
暑假第二周总结博客
QT_QDialog 对话框
【Day_11 0506】求最大连续bit数
极化微波成像概述3









