Java保存图片到数据库Blob格式
1.类
public class PollingDataDTO { private Integer pointId; private byte[] image; public Integer getPointId() { return pointId; } public void setPointId(Integer pointId) { this.pointId = pointId; } public byte[] getImage() { return image; } public void setImage(byte[] image) { this.image = image; } }
2.保存本地图片
// 执行代码 public voidgetImage(Integer pointId) throws Exception { File file = new File("C:\\Users\\Administrator\\Desktop\\002.png"); //本地图片 byte[] b= FileCopyUtils.copyToByteArray(file); PollingDataDTO dto = pollingDataMapper.getByPointId(pointId); dto.setImage(b); pollingDataMapper.updateByPrimaryKey(dto); }