62,616
社区成员
发帖
与我相关
我的任务
分享
public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){
if(pattern.matcher(smsContent).find()){
//return 后直接返回到这里.
processContentCustomer(smsContent,dtoList,customerId);
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}
public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){
if(pattern.matcher(smsContent).find()){
//return 后直接返回到这里.
return processContentCustomer(smsContent,dtoList,customerId); 应该这样
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}
public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){
if(pattern.matcher(smsContent).find()){
//我个人认为:这个是一个个的匹配文件,找到了,就继续递归调用该方法processContentCustomer,直到没有文件,则直接返回smsContent
//return 后直接返回到这里.
processContentCustomer(smsContent,dtoList,customerId);
}else{
//进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事?
return smsContent;
}
}
if(pattern.matcher(smsContent).find()){
processContentCustomer(smsContent,dtoList,customerId);
}else{
//这里返回这个方法
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;
}