首页 > 数据库技术 > 详细

Java保存图片到数据库Blob格式

时间:2020-02-21 16:43:53      阅读:113      评论:0      收藏:0      [点我收藏+]

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);
}

 

Java保存图片到数据库Blob格式

原文:https://www.cnblogs.com/shiblog/p/12341888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!