在Java Spark框架中,如何在根目录下提供静态文件(index.html、CSS、JS) / 使用REST端点,比如 /api/search ?
/
/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 .
/api/搜索
my-static-folder/api/search/index.html
我其实不需要 GET 在…上 /api/search ,我需要一个 POST .使用帖子可以让一切按预期进行:
GET
POST
Spark.post("/api/search", (req, res) -> "rest endpoint");
我不知道该怎么做 收到 工作
收到