在 Spring Boot 中重定向到“/create”时出现问题

问题描述 投票:0回答:1
  • 我有这个
    ProductController.java
    代码片段:
@GetMapping("/create")
public String showCreatePage(Model model) {
    ProductDto productDto = new ProductDto();
    model.addAttribute("productDto", productDto);
    return "products/CreateProduct";
}
  • 我的

    /products
    页面看起来像this

  • 当我点击

    Create New Product
    按钮时,here's我得到的内容
    /products/create
    url

  • 这是我的file hierarchy

  • 这是我的 index.html 来自

    templates/products
    文件夹

  • 这是我的 index.html 来自

    static
    文件夹

我尝试过的:

  • 尝试检查并更改 Thymeleaf 的版本。

  • 在不同的浏览器和 Eclipse IDE 中尝试过。

  • 尝试更改

    CreateProduct.html

    的路径
java spring spring-boot spring-mvc thymeleaf
1个回答
0
投票

你确定是获取端点吗?如果您尝试创建/保存新数据,您应该使用 POST 映射。

© www.soinside.com 2019 - 2024. All rights reserved.