public static String processTemplate(String tpl, Map<String, ?> params){ Iterator<String> it = params.keySet().iterator(); while(it.hasNext()){ String k = it.next(); Object v = params.get(k); String val = v == null ? "" : v.toString(); tpl = tpl.replace("${"+k+"}", val); } return tpl; }
使用事例:
tpl: ${confirmOrganName} ${confirmDepartName} ${confirmDoctorName} ${orderText}${sourceLevelText}门诊。${mydate} params: Map<String, Object> params= new HashMap<String, Object>(); params.put("confirmOrganName", organName); params.put("confirmDepartName", departName); params.put("confirmDoctorName", doctorName); params.put("orderText", confirmClinicTime); params.put("sourceLevelText", sourceLevelTextName); params.put("mydate", mydate);