1. 程式人生 > >Play framework 頁面顯示圖片

Play framework 頁面顯示圖片

我們經常又這樣的需求,使用者上傳圖片到伺服器端,我們需要在瀏覽器上顯示使用者上傳的圖片,

方法如下

public static Result image(String filepath){
    return ok(new File("/home/user/oldcwj/files/"+filepath));
}

routes

GET   /files/*filepath    controllers.Items.image(filepath : String)
*.scala.html
<img src="@routes.Items.image(item.imageUrl)" alt="@item.imageUrl"
/>