当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
【Day_08 0426】求最小公倍数
小贝拉机器人是朋友_普渡科技召开新品发布会,新一代送餐机器人“贝拉”温暖登场...
bat 批示处理详解-2
理财产品的月年化收益率怎么算?
University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
QT_QDialog dialog
QLineEdit学习与使用
极化微波成像概述2
面经汇总-社招-6年
一加OnePlus 10RT出现在Geekbench上 产品发布似乎也已临近
频域分析实践介绍
BITS Pilani|SAC-AP:基于 Soft Actor Critic 的深度强化学习用于警报优先级
公用函数----mfc
SQL的ROUND函数用法及其实例
加州大学|通过图抽象从不同的第三人称视频中进行逆强化学习
【Day_12 0507】二进制插入
关于单应性矩阵的若干思考
ExcelPatternTool: Excel表格-数据库互导工具
Go GORM事务实例分析







