我对 Spring MVC 和 Excel 有疑问。我将excel文件作为lob存储在数据库中。就像我的实体数据库的这一部分是PostgreSQL
@Lob
@Column(name = "Exel")
private String exel;
接下来我想从数据库中获取它,用户可以从网页下载它这是控制器
@RequestMapping(value = "/downloadExelTemplate.xls", method = RequestMethod.GET)
public void downloadExelTemplate(HttpServletResponse response)
throws IOException {
response.setContentType("application/x-msexcel");
ExelDTO exel = service.getExel(new Long(1));
InputStream is = new ByteArrayInputStream(exel.getExel().getBytes());
BufferedWriter outex = new BufferedWriter(new FileWriter("out.xls"));
outex.write(exel.getExel());
outex.close();
ServletOutputStream out = response.getOutputStream();
out.write(exel.getExel().getBytes());
is.close();
out.close();
}
而且我得到的错误 xls 文件不正确。请帮我。怎么了?当我从流中获取文件时,效果是一样的。