是否存在数据库中的图像路径并在视图页面上显示以及如何使用playframework2.0在视图页面中显示图像
答案 0 :(得分:2)
HTML:
@(name:String)
<img class="myClass" alt="myAlt" src="@routes.Application.image(name)">
控制器:
object Application extends Controller {
def image(name:String) = Action {
val MimeType = "image/png"
try {
val imageData: Array[Byte] = fetchImageFromDatabase(name)
Ok(imageData).as(MimeType)
}
catch {
case e: IllegalArgumentException =>
BadRequest("Couldn’t generate image. Error: " + e.getMessage)
}
}
def fetchImageFromDatabase(name: String): Array[Byte] = {
//import java.io.ByteArrayOutputStream
//import java.awt.image.BufferedImage
......
}
}
路线:
GET /images/:name controllers.Application.image(name: String)