无法从postgres查看图像

mccptt67  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(255)

我有一个实体类-产品

@Data
@Entity
@Table(name = "products")
public class Products {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "name")
    @Size(min = 3, max = 40)
    private String name;
    @Column(name = "price")
    @Min(1)
    @Max(10000)
    private int price;
    @Column(name = "serial")
    @Min(1)
    @Max(1000000)
    private int serial;
    @Column(name="picture")
    private byte[] picture; //other code

我正在保存映像的路径:

@Bean
CommandLineRunner runner(ProductService productService, UserService userService) throws IOException {
    byte[] array = Files.readAllBytes(Paths.get("src/main/resources/static/img/mask_black.png"));
    return args -> {
        productService.saveProduct(new Products(11L, "black mask", 100, 11111, array));

在表格中可以看到图像,如650x458,jpeg图像25,45 kb,这是我的html模板:

<tr th:each="products : ${products}">
                <td th:text="${products.name}"></td>
                <td th:text="${products.price}"></td>
                <img src="${products.picture}" width="100" height="100"/> //some other code

但是当我打开一个页面时,我看不到我的图像,只有空的正方形。我做错什么了?p、 我也有repository、service和controller类,但它和任何crud项目一样是标准的。

r9f1avp5

r9f1avp51#

尝试

<img src="data:image/jpg;base64, ${products.picture}">

相关问题