【问题标题】:spring-boot without template engine没有模板引擎的spring-boot
【发布时间】:2015-08-18 12:50:19
【问题描述】:

我有一个显然不合常规的 Spring-Boot 应用程序。它是 Spring-MVC,但我不想使用速度、百里香或任何东西。理想情况下,我只会使用 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 吗?

【问题讨论】:

    标签: spring-mvc spring-boot


    【解决方案1】:

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

    另请参阅Reference Guide

    【讨论】:

    • 谢谢@schlauergerd - 无论如何都不需要url上的html扩展名?理想情况下,输入 localhost/office" 会起作用,但现在我必须附加“.html” 我有 spring.view.prefix=publicspring .view.suffix=html 现在在我的 application.properties 中。
    猜你喜欢
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2022-11-14
    相关资源
    最近更新 更多