Spring 引导 - 提供纯 html 和静态内容
Spring Boot - serving pure html and static content
到目前为止,我已经花了很多时间来完成这个,但仍然无法弄清楚。如何提供纯 .html 页面。这是项目:
https://github.com/robson021/Invoice-Writer
Thymeleaf 引擎工作正常,但如果我尝试 return "regular" .html 文件,我会出错。
Whitelabel Error Page (...) There was an unexpected error
(type=Internal Server Error, status=500). Exception parsing document:
template="test", line 6 - column 3
我承认这是因为我的 "test.html" 文件看起来不像 Thymeleaf 文件。但是我试图从 Maven 的 POM 中删除 Thymeleaf(或在 InteliJ 中创建新项目形式 spring 初始值设定项,没有 Thymeleaf 的项目,只有 Web)并将该 .html 文件放入不同的目录(静态,public, WEB-INF) 仍然失败...我还尝试使用 Java classes 手动配置项目。不幸得到 404 或 500 个错误。
由于这是学校项目,目标是让你的前端独立,我想使用纯 html 和 AngularJS。没有 .jsp 或模板引擎。
谁能告诉我如何让它工作 Spring 引导项目?
编辑:
我的控制器:
@Controller
public class TestController {
@RequestMapping("/test")
public String goToTestPage() {
return "test";
}
}
主要class:
@SpringBootApplication
@EnableAutoConfiguration
public class InvoiceWriterApplication {
public static void main(String\[\] args) {
SpringApplication.run(InvoiceWriterApplication.class, args);
}
}
将 @Controller
替换为 @RestController
-(或者只需将 @ResponseBody
添加到控制器 class 上的 @Contorller
) - 将控制器转换为REST 控制器。
这是因为 @Controller
单独注释会导致 return 值 "home" 映射到模板文件。
此外,为了使 JPA 存储库正常工作,您需要使用 @EnableJpaRepositories
。
到目前为止,我已经花了很多时间来完成这个,但仍然无法弄清楚。如何提供纯 .html 页面。这是项目: https://github.com/robson021/Invoice-Writer
Thymeleaf 引擎工作正常,但如果我尝试 return "regular" .html 文件,我会出错。
Whitelabel Error Page (...) There was an unexpected error (type=Internal Server Error, status=500). Exception parsing document: template="test", line 6 - column 3
我承认这是因为我的 "test.html" 文件看起来不像 Thymeleaf 文件。但是我试图从 Maven 的 POM 中删除 Thymeleaf(或在 InteliJ 中创建新项目形式 spring 初始值设定项,没有 Thymeleaf 的项目,只有 Web)并将该 .html 文件放入不同的目录(静态,public, WEB-INF) 仍然失败...我还尝试使用 Java classes 手动配置项目。不幸得到 404 或 500 个错误。
由于这是学校项目,目标是让你的前端独立,我想使用纯 html 和 AngularJS。没有 .jsp 或模板引擎。
谁能告诉我如何让它工作 Spring 引导项目?
编辑:
我的控制器:
@Controller
public class TestController {
@RequestMapping("/test")
public String goToTestPage() {
return "test";
}
}
主要class:
@SpringBootApplication
@EnableAutoConfiguration
public class InvoiceWriterApplication {
public static void main(String\[\] args) {
SpringApplication.run(InvoiceWriterApplication.class, args);
}
}
将 @Controller
替换为 @RestController
-(或者只需将 @ResponseBody
添加到控制器 class 上的 @Contorller
) - 将控制器转换为REST 控制器。
这是因为 @Controller
单独注释会导致 return 值 "home" 映射到模板文件。
此外,为了使 JPA 存储库正常工作,您需要使用 @EnableJpaRepositories
。