VelocityEngineUtils.mergeTemplateIntoString(.. spring移除了类,没有这个方法的解决办法

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

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();
原文地址:https://www.cnblogs.com/cmmplb/p/15174984.html