DEV Community

Kentama7
Kentama7

Posted on

[Spring Boot]Imgタグに表示する画像をByte配列で返す

  • Kotlin
  • Spring Boot 2.0.4
  • Thymeleaf

Imgタグに表示する画像をByte配列を返すには、ResponseEntityを使用する。

Controllerの実装

@GetMapping("image")
fun image(): ResponseEntity<ByteArray> {
    val bytes = .. // 画像のByte配列を取得
    return ResponseEntity.ok(bytes)
}

HTMLの実装

<img th:src="@{/image}">

Latest comments (0)