Java uses Base64 save the picture to the database and display pictures
Java Base64 save pictures
================================
© Copyright sweet potatoes Yao May 28, 2019
http://fanshuyao.iteye.com/
First, the picture to be saved to the database Base64 blob field
import org.apache.commons.io.FileUtils;
import sun.misc.BASE64Encoder;
/** * 以Base64保存图片到数据库 * @param request * @param file * @throws Exception */ public void saveImage(HttpServletRequest request, File file) throws Exception{ byte[] fileByteArray = FileUtils.readFileToByteArray(file); BASE64Encoder encoder = new BASE64Encoder(); String imageString = encoder.encode(fileByteArray); String sql = "update image_table set image = ? where id = ?"; List<Object> params = new ArrayList<Object>(); params.add(imageString); params.add(1); getDao().update(sql, params); }
================================
© Copyright sweet potatoes Yao May 28, 2019
http://fanshuyao.iteye.com/