首先数据库字段我们要设置为longblob
如下:
实体类字段设置为 byte[]类型
private byte[] byteName;
接下来我们写存入数据库的代码:
@PostMapping(path = "/testFile")
@ResponseBody
public void testFile() throws FileNotFoundException, ClassNotFoundException, SQLException {
//Connection db = null;
File file = new File("D:\\Windchill.zip");
//int length = (int) file.length();
FileInputStream fi = null;
fi = new FileInputStream(file);
lenovoService.testFile(fi);
/*Class.forName("com.mysql.jdbc.Driver");
db = DriverManager.getConnection("jdbc:mysql://service.earth.xpaas.lenovo.com:33051/plmss?useUnicode=true&characterEncoding=utf-8","scmadmin","VcmU1SAlet4fv4bJ");
System.out.pr