我有一个实体类-产品
@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项目一样是标准的。
1条答案
按热度按时间r9f1avp51#
尝试