model view controller - Spring MVC: how to download Excel from DB -
i have problem spring mvc , excel. store excel file in database lob. part of entity database postgresql
@lob @column(name = "exel") private string exel;
next db , user can download web page controller
@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 = 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(); }
and not proper xls file bugs. please me. wrong? when file stream same effect.
so resolve problem, change type of data in hibernate entity to
@lob byte[] exeldata;
and work well. when there text file there no problem mapping @lob string connected ms office formats fails. learned how keep data file correctly.
Comments
Post a Comment