当前位置:网站首页>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的多功能指纹智能锁

B011 - 51-based multifunctional fingerprint smart lock

2022年SQL大厂高频实战面试题(详细解析)

SQL窗口函数

Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读

实现mnist手写数字识别

打开微信客服

How to build a CMDB driven by consumption scenarios?

B001 - 基于STM32的智能生态鱼缸

Golang协程调度器scheduler怎么使用
随机推荐
SQL窗口函数
OpenCV安装、QT、VS配置项目设置
Go GORM事务实例分析
移动端吸顶方案
分布式消息队列平滑迁移技术实战
ExcelPatternTool: Excel表格-数据库互导工具
【Day_08 0426】两种排序方法
使用设备树时对应的驱动编程
【Day_08 0426】求最小公倍数
opencv如何实现图像倾斜校正
MySQL Lock wait timeout exceeded; try restarting transaction 锁等待
QT基础功能,信号、槽
极化微波成像概述2
【Day_09 0427】 另类加法
tooltip 控件
C language theory--a solid foundation for the written test and interview
How opencv implements image skew correction
AIOps智能运维的领跑者擎创科技正式入驻InfoQ 写作社区!
SQL的索引详细介绍
三维空间中点的插值