我是Java Spring启动的新手。 -
我可以访问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();
}
答案 0 :(得分:0)
Spring已经开箱即用,您可以将这些路径映射到静态URI。
您需要做的是,定义一个Spring Configuration类,使用WebMvcConfigurerAdapter扩展它
这将允许您访问addResourceHandlers方法,覆盖该方法并提供静态资源的路径以及要将其映射到的URI。我提供了另一个SO答案的链接,它做了同样的事情。
Spring 4 loading static resources
Spring 4 - addResourceHandlers not resolving the static resources