public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){if(pattern.matcher(smsContent).find()){
//return 后直接返回到这里.
processContentCustomer(smsContent,dtoList,customerId);
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}
//return 后直接返回到这里.
processContentCustomer(smsContent,dtoList,customerId);
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
return smsContent;}
/**
* 处理客户标记
* @param smsContent
* @param dtoList
* @param customerId
* @return
*/
public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){
String regex = "\\{(\\w)*\\}";
//得到SmsSignUserDto 的所有属性
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(smsContent);
if (matcher.find()) {
for(SmsSignCustomerDto dto:dtoList){
String replace = smsContent.substring(matcher.start(), matcher.end());
String sign = replace.substring(1, replace.length()-1);
String stringLetter = sign.substring(0, 1).toUpperCase();
// 获得相应属性的getXXX和setXXX方法名称
String getName = "get" + stringLetter + sign.substring(1);
if(customerId == null){
return smsContent;
}
if(!customerId.equals(dto.getCustomerCode())){
continue;
}
Method method;
try {
method = dto.getClass().getDeclaredMethod(getName, null);
Object result = method.invoke(dto, null);
String rs = smsContent.replace(replace, result.toString());
smsContent = rs;
} catch (SecurityException e) {
return smsContent;
} catch (NoSuchMethodException e) {
return smsContent;
} catch (IllegalArgumentException e) {
return smsContent;
} catch (IllegalAccessException e) {
return smsContent;
} catch (InvocationTargetException e) {
return smsContent;
}
if(pattern.matcher(smsContent).find()){
processContentCustomer(smsContent,dtoList,customerId);
}else{
return smsContent;
}
}
}
return smsContent;
}
完整的方法是这样的.
if(pattern.matcher(smsContent).find()){
processContentCustomer(smsContent,dtoList,customerId);
}else{
//这里返回这个方法
return smsContent;
}
processContentCustomer(smsContent,dtoList,customerId);
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}就是一个递归的调用啊,亲……
参数 smsContent 为这天内容,List<SmsSignCustomerDto> dtoList 为用存储过程查询出来管理要修改{XX}的数据, customerId 为要和 dtoList 某一条数据的ID 相同, 才说明 dtoList 里面的数据是属于 这个customer的. 描述能力不行, 请谅解.
//return 后直接返回到这里.
return processContentCustomer(smsContent,dtoList,customerId); 应该这样
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}