【发布时间】:2020-11-17 09:15:29
【问题描述】:
我有 base64 字符串,我想使用 Spring 的 restcontroller 在 img 标签上打印 base64 图像。
我正在分别开发正面和背面。
这是我的休息控制器
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@Validated
public class TestController {
@RequestMapping(value = "/image/test", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
public byte[] getImage() throws Exception {
String base64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYIAAACzCAY...."; //from DB
byte[] decodeBase64 = Base64.decodeBase64(base64);
return decodeBase64;
}
}
这是我的html
<html>
<body>
<img src="http://localhost:8080/myProject/image/test"/>
<body/>
</html>
图像不输出。有什么问题?
【问题讨论】:
-
阅读“数据 URL”,然后看看您是否可以确定您需要使用该字符串的哪个部分。
标签: java html spring image base64