例如:
    
    尊敬的${userName}先生/女士:
   
    您在
    
     
      
       n 
e
w
T
i
m
e
时
间
,
        {newTime}时间,
      
      
       
        
        
        
         
          n
         
         
          e
         
         
          w
         
         
          T
         
         
          i
         
         
          m
         
         
          e
         
        
        
         时
        
        
         间
        
        
         ,
        
       
      
     
    
    {}地点,消费了
    
     
      
       人 
名
币
/
美
元
/
等
等
币
种
,
出
库
单
号
为
:
        {}人名币/美元/等等币种, 出库单号为:
      
      
       
        
        
        
        
        
         人
        
        
         名
        
        
         币
        
        
         /
        
        
         美
        
        
         元
        
        
         /
        
        
         等
        
        
         等
        
        
         币
        
        
         种
        
        
         ,
        
        
         出
        
        
         库
        
        
         单
        
        
         号
        
        
         为
        
        
         :
        
       
      
     
    
    {}
   
网上订单号为${},将有 ${}(韵达) 承运, 等等
通过调用这个模板时把对应的动态数据传过去,
String content = MailUtils.getMailText(map, sysMailTemplate.getContent());//这里面传的参map为动态用户数据,sysMailTemplate为模板内容
//通过模板构造邮件内容,将模板中的变量替换成map中的值,注:模板中的变量与map中的key保持一致。       
    public static String getMailText(Map<String, Object> map, String htmlTemplate) {
        String htmlText = htmlTemplate;
        //遍历Map中的所有Key,将得到的value值替换模板字符串中的变量值
        Set<String> keys = map.keySet();
        for (Iterator<String> it = keys.iterator(); it.hasNext();) {
            String key = it.next();
            htmlText = htmlText.replace("${" + key + "}", (String) map.get(key));
        }
        return htmlText;
    }
    类似这种办法就可以动态显示邮件的内容,然后获取到内容发邮件或者短信。
    
    方法2
   
 variables = (Map<String, String>) JSONArray.parse(entity.getVariables());
 for (String s : variables.keySet()) {
                String replaceContent = "${" + s + "}";
                if (content.contains(replaceContent)) {
                    try {
                        String code = variables.get(s);
                        content = content.replace(replaceContent, code);
                    } catch (Exception e) {
                   	    return CodeEnum.UnknownException.getType();
                    }
                }
            }