无法导入 org.thymeleaf.templatemode.TemplateMode [英] Can not import org.thymeleaf.templatemode.TemplateMode
问题描述
我正在学习以下教程,该教程基于使用 Thymeleaf 模板发送电子邮件.
I'm following the below tutorial which is based on sending an email using Thymeleaf template.
教程链接:http://www.thymeleaf.org/doc/articles/springmail.html
在此示例中,TemplateMode 用于多个实例
In this example TemplateMode is being used in several instances
private ITemplateResolver textTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(Integer.valueOf(1));
templateResolver.setResolvablePatterns(Collections.singleton("text/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".txt");
templateResolver.setTemplateMode(TemplateMode.TEXT);
templateResolver.setCharacterEncoding(EMAIL_TEMPLATE_ENCODING);
templateResolver.setCacheable(false);
return templateResolver;
}
private ITemplateResolver htmlTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setOrder(Integer.valueOf(2));
templateResolver.setResolvablePatterns(Collections.singleton("html/*"));
templateResolver.setPrefix("/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCharacterEncoding(EMAIL_TEMPLATE_ENCODING);
templateResolver.setCacheable(false);
return templateResolver;
}
当我搜索它时,我发现它在 org.thymeleaf.templatemode.TemplateMode 中,但我无法将它导入到我的项目中
While I was searching for it I found it is in org.thymeleaf.templatemode.TemplateMode but I cant import it to my project
所以 TemplateMode 给了我错误.如何修复错误?
So TemplateMode gives me errors. How to fix the error?
推荐答案
org.thymeleaf.templatemode.TemplateMode
已在 Thymeleaf 3.0.0 中添加.
The class org.thymeleaf.templatemode.TemplateMode
was added in Thymeleaf 3.0.0.
只要您依赖于 Thymeleaf >= 3.0.0 的版本,那么 TemplateMode
将可供您使用,因此 TemplateMode
在您的项目中不可用的事实classapth 强烈 暗示您使用的是 Thymeleaf 版本3.0.0.
As long as you depend on a version of Thymeleaf >= 3.0.0 then TemplateMode
will be available to you so the fact that TemplateMode
is not available on your project's classapth strongly implies that you are using a version of Thymeleaf < 3.0.0.
最重要的是,您链接到的示例使用了 Thymeleaf >= 3.0.0
而您使用的是 Thymeleaf <3.0.0
.
The bottom line is that the example you linked to uses Thymeleaf >= 3.0.0
whereas you are using Thymeleaf < 3.0.0
.
FWIW,你的问题也标记了 spring
所以也许你是通过传递获取你的 Thymeleaf 依赖(通过 spring-boot-starter-thymeleaf
也许?).您可以运行 mvn dependency:tree
并查看以下输出:org.thymeleaf:thymeleaf
以了解 (a) 您使用的是哪个版本的 Thymeleaf 以及 (b)版本来自.
FWIW, your question also tags spring
so perhaps you are acquiring your Thymeleaf dependency transitively (via spring-boot-starter-thymeleaf
perhaps?). You could run mvn dependency:tree
and review the output for: org.thymeleaf:thymeleaf
to understand (a) what version of Thymeleaf you are using and (b) where this version comes from.
这篇关于无法导入 org.thymeleaf.templatemode.TemplateMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!