美文网首页
Zeus-参数体系

Zeus-参数体系

作者: PunyGod | 来源:发表于2016-07-08 11:46 被阅读222次

    Zeus使用org.apache.velocity 来处理参数的动态替换。

    
    public static String render(String template){
       if(template==null){
          return null;
       }
       Matcher matcher=pt.matcher(template);
       while(matcher.find()){
           String m= template.substring(matcher.start(),matcher.end());
           StringWriter sw=new StringWriter();
           try {
             VelocityContext context=new VelocityContext();
             context.put("zdt", new ZeusDateTool());
             Velocity.evaluate(context, sw, "", m);
             if(m.equals(sw.toString())){
                //渲染后和原数据一样,则直接跳出,如果不跳出会导致死循环
                log.error("render fail with target:"+m);
                break;
             }
          } catch (Exception e) {
             log.error("zdt render error",e);
             break;//防止死循环
          }
           template=template.replace(m, sw.toString());
           matcher=pt.matcher(template);
       }   //${yesterday}变量替换
       template=template.replace("${yesterday}",new ZeusDateTool().addDay(-1).format("yyyyMMdd"));
       return template;
    }
    

    但是Zeus支持的参数表达式很少;

    相关文章

      网友评论

          本文标题:Zeus-参数体系

          本文链接:https://www.haomeiwen.com/subject/ejtrjttx.html