当前位置:网站首页>消息模板占位符的使用
消息模板占位符的使用
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 can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.
- QT_事件类
- 解决MySQL插入不了中文数据问题
- 粒子滤波 particle filter —从贝叶斯滤波到粒子滤波——Part-I(贝叶斯滤波)
- 千万级乘客排队系统重构&压测方案总结篇
- B011 - 基于51的多功能指纹智能锁
- C#/VB.NET:从 PDF 文档中提取所有表格
- 关于Mysql服务无法启动的问题
- 浅谈大数据背景下数据库安全保障体系
- What is the JVM runtime data area and the JMM memory model
猜你喜欢
随机推荐
关于LocalDateTime的全局返回时间带“T“的时间格式处理
2022年SQL经典面试题总结(带解析)
TCP million concurrent server optimization parameters
【Day_12 0507】查找组成一个偶数最接近的两个素数
University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction
QT commonly used global macro definitions
SQL函数 TO_DATE(二)
tooltip control
QT_QThread线程
How to solve the dynamic binding of el-form-item prop attribute does not take effect
Go iota关键字与枚举类型实现原理是什么
移动端吸顶方案
How opencv implements image skew correction
关于单应性矩阵的若干思考
基于BiGRU和GAN的数据生成方法
gtk显示4通道rgba图像
Leetcode72. 编辑距离
快速抽取resnet_v2_152中间的特征层
QT常用全局宏定义
RecSys'22|CARCA: Cross-Attention-Aware Context and Attribute Recommendations









