spring-不使用模板引擎启动

spring-boot without template engine

我有一个 Spring- 启动应用程序,它显然不符合规范。它是 Spring-MVC,但我不想使用 velocity、thymeleaf 或任何东西。理想情况下,我只使用 HTML。然后我使用 jQuery 对我的 REST 服务进行 AJAX 调用,然后用返回的 JSON 填充页面。我主要可以让它工作的唯一方法是将我的 html 放在 /src/resources/templates 下,然后为每个页面设置一个 @Controller。所以我有:

@SpringBootApplication

public class Application {
    public static void main(String[] args) throws Throwable {
        SpringApplication.run( Application.class, args );
    }
}

和我的控制器

@Controller
public class HomeController {
    @RequestMapping("/")
    public String getHome() {
        return "index"
}

@Controller
public class AboutController {
    @RequestMapping("/about")
    public String getAbout() {
        return "about"
}

我已经查看了 Spring 指南和示例项目,但我不知道如何配置它。我正在使用入门项目来获得 spring-mvc 和安全性,但除此之外我看不到我需要做什么,所以导航到 :

localhost/homelocalhost/aboutlocalhost/customer

或者,是不是每个页面都必须有一个@Controller?

如果您想使用 HTML 和 JavaScript 等静态资源,您可以将它们放入名为 /public/static/src/main/resources 的子文件夹中/resources。例如,位于 /src/main/resources/public/dummy/index.html 的文件可以通过 http://localhost/dummy/index.html 访问。您不需要控制器。

另见 Reference Guide