繁体   English   中英

SpringBoot Starter Project-错误解决模板

[英]SpringBoot Starter Project - Error resolving template

我正在编写一个JUnit测试,该测试应该测试html页面的标题。 该项目是SpringBoot Thymeleaf入门项目。

HtmlPath:

private final static String HTML_PATH = "/pages/dashboard/dashboard.html";

JUnitTest:

@Test
public void shouldRenderPageTitle() throws IOException, NodeSelectorException {
    Map<String,Object> model = new HashMap<>();
    model.put("pageTitle", "expected title");
    HtmlElements tags = testEngine.process(HTML_PATH, model);
    assertThat(tags.matching("title"), isSingleElementThat(hasOnlyText("expected title")));
}

ThymeleafConfiguration

@Configuration
public class ThymeleafConfig {

@Bean
public TemplateResolver templateResolver() {
    TemplateResolver templateResolver = new TemplateResolver();
    templateResolver.setPrefix("/resources/templates/");
    return templateResolver;
}

@Bean
public SpringTemplateEngine templateEngine() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver());
    templateEngine.addDialect(new LayoutDialect());
    templateEngine.addDialect(new SpringStandardDialect());
    return templateEngine;
}

@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(templateEngine());
    return viewResolver;
}

}

错误:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/pages/dashboard/dashboard.html"

ir树

你必须用
私有最终静态字符串HTML_PATH =“ / pages / dashboard / dashboard”; //没有“ .html”

您可以尝试替换此行代码吗

templateResolver.setPrefix("/resources/templates/");

与这个

templateResolver.setPrefix("templates/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM