图片通过Base64字符串在画面上显示
这里图片在数据库的存储是将图片转化为byte[]保存的,所以从数据库取出的图片为byte[]。
首先将byte[]转化为Base64字符串
1 // 获取图片 2 byte[] bytes = imageRepository.getImage(); 3 // Base64字符串 4 String imageStr = Base64.getEncoder().encodeToString(bytes);
将得到的字符串传到画面显示
<img src="data:image/png;base64,${imageStr}"/>