尝试将图像base64保存到spring boot数据库中的byte []中
我使用的 https://codebeautify.org/image-to-base64-converter 网站将图像转换为 base64 https://unsplash.com/photos/KaK2jp8ie8s 我正在使用图像,
因此请正确使用图像和网站多于。我正在将此图像转换为 base64,并尝试将其保存到我的 spring boot h2 数据库中。它不会让我说它不是一个 byte[]。我怎样才能做到呢?
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Data
public class Fromage implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nom;
private double prix;
private int vieillese;
private int quantite;
@Lob
private byte[] data;
public Fromage(){}
public Fromage(String nom, double prix, int vieillese, int quantite, byte[] data) {
this.nom = nom;
this.prix = prix;
this.vieillese = vieillese;
this.quantite = quantite;
this.data = data;
}
}
byte[] bob = {1,2,3};
Fromage fromage = new Fromage("Chevre",50.15,10,1,bob);
fromageRepository.save(fromage);
尝试执行此操作,但将 bob 替换为图像 base64 字符串
https://codebeautify.org/image-to-base64-converter website I use to convert image to base64
https://unsplash.com/photos/KaK2jp8ie8s image I am using
so using the image and website right above. I am converting this image into base64 and I am trying to save it into my spring boot h2 database. It won't let me saying it is not a byte[]. How could I do it?
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Data
public class Fromage implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nom;
private double prix;
private int vieillese;
private int quantite;
@Lob
private byte[] data;
public Fromage(){}
public Fromage(String nom, double prix, int vieillese, int quantite, byte[] data) {
this.nom = nom;
this.prix = prix;
this.vieillese = vieillese;
this.quantite = quantite;
this.data = data;
}
}
byte[] bob = {1,2,3};
Fromage fromage = new Fromage("Chevre",50.15,10,1,bob);
fromageRepository.save(fromage);
trying to do this but replace bob with image base64 string
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论