代码之家  ›  专栏  ›  技术社区  ›  Joe

通过重叠路径(如/api/search)提供Java Spark静态文件

  •  0
  • Joe  · 技术社区  · 6 年前

    在Java Spark框架中,如何在根目录下提供静态文件(index.html、CSS、JS) / 使用REST端点,比如 /api/search ?

      public static void main(String[] args) {
        Spark.staticFiles.location("/");
        Spark.staticFiles.externalLocation("my-static-folder");
        Spark.get("/api/search", (req, res) -> "rest endpoint");
      }
    

    在上面的例子中,Spark不会使用 /api/搜索 终点。相反,它将发挥作用 my-static-folder/api/search/index.html .

    1 回复  |  直到 6 年前
        1
  •  0
  •   Joe    6 年前

    我其实不需要 GET 在…上 /api/search ,我需要一个 POST .使用帖子可以让一切按预期进行:

    Spark.post("/api/search", (req, res) -> "rest endpoint");
    

    我不知道该怎么做 收到 工作

    推荐文章