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