gpt4 book ai didi

java - 如何构建包含 vaadin 路由和静态 html 页面的 Spring boot 项目

转载 作者:行者123 更新时间:2023-12-02 06:01:36 33 4
gpt4 key购买 nike

我正在使用 spring bootvaadin 和一些静态 html 页面(如 bootstrap 等 UI 框架)构建一个 Web 应用程序。

我想在我的项目中同时拥有 Vaadin 路由和静态 html 页面。

静态页面只是一个基本的index.html页面,其中包括一些cssjs

1) 如果我将 index.html 放在 webapp 文件夹中,则可以从 www.localhost:8080/ url 访问它,但随后我收到来自 vaadin 的错误,说:

the back-end doesn't accept POST requests to www.localhost:8080/

(因为 vaadin 实际上向该 url 发送 POST 请求)

2) 如果我添加一个 @Route("") 类,则 index.html 无法访问躺椅,但后端会接受 POST来自 vaadin 客户端的请求...

3)我不知道如何将静态 html 导入到 @Route 类。 (@HtmlImport 没办法)

有什么想法吗?

最佳答案

如果您有一个 spring-boot 启动器 vaadin 应用程序,那么下面应该可以工作:

1) 将静态页面(例如 test.html)放置在 resources/static 下。 (在 Add a Home Page section 下有一个来自 Spring 官方演示页面的示例,其中包含有关相应文件夹的简短说明)

2) 之后使用 @Controller 注解类指定映射规则


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class GreetingController {

@GetMapping(value = "/ownPage")
public String index() {
return "test.html";
}

}

3) 导航到 yourURL\ownPage@GetMapping 内指定的任何路径值。这将返回 test.html 页面

关于java - 如何构建包含 vaadin 路由和静态 html 页面的 Spring boot 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55972257/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com