首页 > 解决方案 > 如何在spring boot中访问外部项目资源

问题描述

我正在用 SpringBoot 建立一个网站。目前使用百里香。

我目前正在运行 3 个项目,每个项目名为 ko, en, payment。

我目前的情况是通过单击 en 项目内 purchase.html 中的按钮来发送邮件。

发送邮件负责支付项目。

原因是在 en 项目中单击 purchase.html 中的按钮时要实现相同的功能。

在任何情况下,在发送电子邮件时,都会使用单独的 html 作为内容来撰写电子邮件内容。

ApplicationContext context = new AnnotationConfigApplicationContext(ThymeleafViewResolverConfig.class);
        Context ctx = new Context(Locale.KOREA);
        ctx.setVariable("name", purchaseModel.getReceiverManagerName() + "님");
        TemplateEngine templateEngine = context.getBean(TemplateEngine.class);
        final String htmlContent = templateEngine.process("orderMailTemplate_ko", ctx);
        textBodyPart.setContent(htmlContent, "text/html; charset=UTF-8");

当调用外部 html 时,它是使用模板引擎导入的,如下面的代码。

所以我尝试的是:

<img th:src="@{/img/test.jpg}" `<img th:src="@{img/test.jpg}"

仍然存在尝试加载失败的情况。

于是我搜索了如何加载外部项目资源,但找不到合适的解决方案。

请给我一个提示。

标签: spring-bootresourcesthymeleaf

解决方案


推荐阅读