[英]Spring MVC - accessing a static page through Thymeleaf
我有一個Spring Boot Web應用程序,使用嵌入式Tomcat + Thymeleaf模板引擎,並將package作為可執行JAR文件。
使用的技術:
Spring Boot 1.4.2.RELEASE,Spring 4.3.4.RELEASE,Thymeleaf 2.1.5.RELEASE,Tomcat Embed 8.5.6,Maven 3,Java 8
我想訪問位於../src/main/resources/templates/mockups/index.html
的靜態文件
所以我創建了這個控制器:
@Controller
public class MockupIndexController {
@RequestMapping("/mockup/index")
public String welcome(Map<String, Object> model) {
return "/mockups/index.html";
}
}
但是我收到了這個錯誤:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/mockups/index.html", template might not exist or might not be accessible by any of the configured Template Resolvers
在spring xml配置文件中,映射你的靜態文件位置,請將靜態文件保存在不同的文件夾中
<mvc:resources mapping = "/mockups/**" location = "/src/main/resources/templates/mockups/" />
改變這一行
return "/mockups/index.html";
至
return "redirect:/mockups/index.html";
如果您沒有使用配置文件,請添加此類
@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/mockups/**").addResourceLocations("/src/main/resources/templates/mockups/");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.