Document

之前的版本创建邮件发送的方式:

String text = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, "模板名称.vm", "UTF-8", model);

 

由于VelocityEngineUtils类移除,用这个方式创建:

        VelocityEngine velocityEngine = new VelocityEngine();
        Properties p = new Properties();
        p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "src/main/resources/templates");
        velocityEngine.init(p);

        Map<String, Object> model = new HashMap<>();
        model.put("模板参数", "值");
        VelocityContext velocityContext = new VelocityContext(model);
        StringWriter writer = new StringWriter();
        velocityEngine.mergeTemplate("template.vm", "UTF-8", velocityContext, writer);
        String text = writer.toString();

 

posted on 2021-08-23 10:51  夏目co  阅读(489)  评论(0编辑  收藏  举报