簡體   English   中英

Java Spring Boot-獲取電子郵件的圖像路徑以在Freemarker中工作

[英]Java Spring Boot - getting images paths for emails to work in Freemarker

我是Java Spring Boot的新手。 --

我可以訪問Freemarker演示-但是如何獲得“ \\ src \\ main \\ resources \\ static \\ images”的圖像路徑

            //Map < String, Object > model = new HashMap < String, Object > ();
            model.put("firstName", "Yashwant");
            model.put("lastName", "Chavan");
            model.put("imgPath", "resources/static/images/");

            mimeMessageHelper.setText(geContentFromTemplate(fmConfiguration, model), true);

            mailSender.send(mimeMessageHelper.getMimeMessage());
        } catch (MessagingException e) {
            System.out.println("ERROR - mimeMessage>>>");
            e.printStackTrace();
        }        
    }

}

public String geContentFromTemplate(Configuration fmConfiguration, Map < String, Object > model) {
    StringBuffer content = new StringBuffer();

    try {
        content.append(FreeMarkerTemplateUtils
            .processTemplateIntoString(fmConfiguration.getTemplate("email-template.html"), model));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return content.toString();
}

Spring已經提供了開箱即用的功能,您可以在其中將這些路徑映射到靜態URI。

您需要做的是,定義一個Spring Configuration類,並使用WebMvcConfigurerAdapter對其進行擴展

這將使您可以訪問addResourceHandlers方法,覆蓋該方法,並提供靜態資源的路徑以及要使用其映射的URI。 正在提供指向執行相同操作的另一個SO答案的鏈接。

Spring 4加載靜態資源

春季4-addResourceHandlers無法解析靜態資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM