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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM