PlayScala 2.5.x - 訪問public目錄靜態文件的三種方法

  1. 經過routes文件定義
GET     /favicon.ico       controllers.Assets.at(path="/public", file="favicon.ico")
GET     /assets/*file      controllers.Assets.versioned(path="/public", file: Asset)
  1. 經過Assets生成的action訪問
controllers.Assets.versioned(path="/public", file="html/index.html")(request)
controllers.Assets.at(path="/public", file="html/index.html")(request)
  1. 直接生成File Result
Ok.sendFile(new File("public/html/index.html")).as("text/html; charset=UTF-8")
Ok.sendPath(Paths.get("public/html/index.html")).as("text/html; charset=UTF-8")
相關文章
相關標籤/搜索