关于SSM的图片插入和获取
2019-04-15 12:54发布
生成海报
实体类和mybatis配置
public class Pic{
private String pic;
public String getPic(){
return pic;
}
public void setPic(String pic){
this.pic = pic == null ? null : pic.trim();
}
}
public interface PicMapper{
int insert(Pic pic);
List selectAll();
}
在oracle插入CLOB格式图片
首先获取到图片,方式有很多,这只取了一种:
FileInputStream fis = new FileInputStream("D:/321.bmp");
int av = fis.available();
byte[] buff = new byte(av);
fis.read(buff);
fis.close();
Encoder encoder = Base64.getEncoder();
String pic = encoder.encodeToString(buff);
Pic myPic = new Pic();
mypic.setPic(pic);
picMapper.insert(mypic);
获取CLOB格式图片
List list = picMapper.selectAll();
for(Pic pic : list){
Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(pic.getPic());
String returnStr = new String(bytes);
}
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮