在我的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
错误。我要去哪里错了?