Spring Boot静态HTML不显示模型数据

时间:2019-04-22 18:23:50

标签: spring-boot spring-mvc

在我的Controller中,我将返回model对象,如下所示:

----
modelAndView.addObject("confirmMessage",
            "User is successfully registered. Please follow the instructions sent to your email for activation.");
modelAndView.setViewName("redirect:/success.html");
        return modelAndView;

我在success.html目录中有static文件。文件已加载,但样式表未加载。

<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <!-- include css in the header -->
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/4.3.1/css/bootstrap.min.css}" />
</head>
<body>

<div class="container">
    <h1>
        <!-- include image from static resources -->
        Adding Static Resources (css, JavaScript, Images) to Thymeleaf
    </h1>
</div>

</body>
</html>

我已将webjar配置为pom.xml文件中的依赖项,对于资源目录下的所有thymeleaf模板,引导程序文件已加载,但不适用于此页面。我什至无法提取添加到模型对象中的数据。

我添加了一个配置类

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(
                "/webjars/**")
                .addResourceLocations(
                        "classpath:/META-INF/resources/webjars/",
                        "classpath:/static/");
    }

}

添加上述内容后,我收到404错误。我要去哪里错了?

0 个答案:

没有答案