当前位置:网站首页>消息模板占位符的使用
消息模板占位符的使用
2022-08-01 18:01:00 【勉之~】
消息模板占位符的使用
一 具体实现
说明:根据@占位符进去匹配占位
案例:“模板名称:@[email protected],发生了变更,变更描述:@[email protected]的变更描述是:@[email protected]”;
1. 占位符解析
//解析占位符拼接消息模板
public String getContent(MsgType msgType, Map<String, String> messageAttrMap) {
//获取带占位符的消息模板
String result = messageTypeRepo.getByCode(msgType.name()).getContentTemplate();
//result = "模板名称:@[email protected],发生了变更,变更描述:@[email protected]的变更描述是:@[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. 占位符参数的赋值
@ApiModelProperty(value = "消息模板类型",required = true)
private MsgType msgType;
@ApiModelProperty(value = "消息内容的属性",required = true)
private Map<String, String> msgAttrMap;//key可能有重复的属性字段,需要替换,value则为替换的字段的值,用于消息模板的占位
边栏推荐
- How to solve the dynamic binding of el-form-item prop attribute does not take effect
- 行业沙龙第二期丨如何通过供应链数字化业务协同,赋能化工企业降本增效?
- 2022年SQL经典面试题总结(带解析)
- 面经汇总-社招-6年
- 生物制药产业发展现状和趋势展望
- QLineEdit learning and use
- golang json 返回空值
- Topology Parts Disassembly 3D Visualization Solution
- QT_QThread thread
- BITS Pilani|SAC-AP:基于 Soft Actor Critic 的深度强化学习用于警报优先级
猜你喜欢
随机推荐
Detailed explanation of DBPack SQL Tracing function and data encryption function
浅谈大数据背景下数据库安全保障体系
QT常用全局宏定义
中信证券是国内十大券商吗?怎么开户安全?
数字化采购管理系统开发:精细化采购业务流程管理,赋能企业实现“阳光采购”
生物制药产业发展现状和趋势展望
Leetcode73. 矩阵置零
How to use the Golang coroutine scheduler scheduler
TCP million concurrent server optimization parameters
面经汇总-社招-6年
Leetcode74. Search 2D Matrix
QT_QDialog 对话框
MySQL 45 Talk | 09 How to choose common index and unique index?
Leetcode71. 简化路径
tooltip 控件
【Day_08 0426】求最小公倍数
关于MySql中explain结果filtered的理解
QT_QDialog dialog
【Translation】OpenMetrics cultivated by CNCF becomes an incubation project
食品安全 | 新鲜食品vs速食食品,哪一种是你的菜?