org.thymeleaf.exceptions.TemplateInputException:模板解析期间发生错误(模板:“ WEB-INF / view / index.html”)

时间:2019-05-13 21:36:38

标签: html spring thymeleaf

我有问题。我收到500错误:

  

templateResolver找不到index.html的路径

     

错误org.springframework.web.util.NestedServletException。

我已经附上我的代码

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.noteapp.controller")
public class WebConfig extends WebMvcConfigurerAdapter {




    @Bean
    @Description("Thymeleaf template resolver serving HTML 5")
    public ClassLoaderTemplateResolver templateResolver() {

        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setPrefix("WEB-INF/");
        templateResolver.setCacheable(false);
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode("HTML5");
        templateResolver.setCharacterEncoding("UTF-8");

        return templateResolver;

    }

    @Bean
    @Description("Thymeleaf template engine with Spring integration")
    public SpringTemplateEngine templateEngine() {

        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());

        return templateEngine;
    }

    @Bean
    @Description("Thymeleaf view resolver")
    public ViewResolver viewResolver() {
        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine());
        viewResolver.setCharacterEncoding("UTF-8");


        return viewResolver;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GOOD GAME</title>
</head>
<body>
    <a href="/hello">
        <h1>
            click
        </h1>
    </a>
</body>
</html>

0 个答案:

没有答案