public static String processContentCustomer(String smsContent,List<SmsSignCustomerDto> dtoList,String customerId){if(pattern.matcher(smsContent).find()){
        //return 后直接返回到这里.
processContentCustomer(smsContent,dtoList,customerId);
}else{
        //进入这里并没有返回到方法的顶部 ,而是上面的那个的这个方法是怎么回事? 
return smsContent;
}
}

解决方案 »

  1.   

    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 smsContent;}
      

  2.   


    /**
     * 处理客户标记
     * @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;
    }
    完整的方法是这样的.
      

  3.   

    我怎么在
     if(pattern.matcher(smsContent).find()){
                            processContentCustomer(smsContent,dtoList,customerId);
                        }else{
    //这里返回这个方法
                            return smsContent;
        }
      

  4.   

    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;
    }
    }就是一个递归的调用啊,亲……
      

  5.   

    我就是想把 一条像这样的内容:尊敬的{XX}你的卡上余额为{XX} 把{XX}全部替换成 数据库中取出的数据
    参数 smsContent 为这天内容,List<SmsSignCustomerDto> dtoList 为用存储过程查询出来管理要修改{XX}的数据, customerId 为要和 dtoList 某一条数据的ID 相同, 才说明 dtoList 里面的数据是属于 这个customer的. 描述能力不行, 请谅解.
      

  6.   

    你这不会报错奇迹 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;
    }
    }