![](/img/trans.png)
[英]Freemarker templates unable to gain access to images - Java Spring Boot
[英]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答案的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.