我正在开发一个项目,其中有一张带有图像的表格。我需要将图像存储为 LONGBLOB。应用程序在Spring Boot中实现,应用程序启动时应生成MySQL数据库。 Spring Boot中有没有办法指定LONGBLOB?
现在我正在使用 @Lob 注释,但它会生成 TINYBLOB 类型的列。
@Data
@Entity
@Table(name = "image")
public class ImageEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "id_image")
private Integer idImage;
@Basic
@Lob
@Column(name = "image",nullable = false)
private byte[] image;
}
我设法找到了解决方案,只需在 @Column 注释中添加类型定义即可。
@Data
@Entity
@Table(name = "image")
public class ImageEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "id_image")
private Integer idImage;
@Basic
@Column(name = "image",nullable = false, columnDefinition="LONGBLOB")
private byte[] image;
}