正则替换文本内容

 
 
 
 
 
 
KeySet():
将Map中所有的键存入到set集合。set具备迭代器。所有可以迭代取出所有的键,
再根据get方法。获取每一个键对应的值。 
entrySet():
Set<Map.Entry<K,V>> entrySet() //返回此映射中包含的映射关系的 Set 视图。
 Map.Entry表示映射关系。entrySet():迭代后可以e.getKey(),
e.getValue()取key和value。返回的是Entry接口 。

String re = emailTemplate.getTemplateValue();
//遍历map集合K,V
for (Map.Entry<String,String> map:messageDTO.getParams().entrySet()) {
    //通过正则匹配字符串匹配的参数
    re = re.replaceAll("\\{"+map.getKey()+"\\}",map.getValue());
}

猜你喜欢

转载自blog.csdn.net/qq_39438729/article/details/79497084