def result = [code: 200, msg: "success"] def sql = new Sql(dataSource); def files = sql.rows("select * from T_SYS_attachmentInfoUse where pk = 1") //将字节数组装换成字节数组流 def fileBytes = new ByteArrayInputStream(files[0].image) // FileInputStream fileBytes = new FileInputStream("D:/A1.png") OutputStream out = response.getOutputStream() def buf = new byte[1024 * 5] int len = 0 // 循环将输入流中的内容读取到缓冲区中 while ((len = fileBytes.read(buf)) > 0) { // 输出缓冲区内容到浏览器,实现文件下载 // response.outputStream.write(buf, 0, len) out.write(buf, 0, len) } // out.close() fileBytes.close()