日期:2014-05-16 浏览次数:20663 次
<bean id="defaultLobHandler" ?? class="org.springframework.jdbc.support.lob.DefaultLobHandler" ?? lazy-init="true" />
@Resource private LobHandler lobHandler;
jdbcTemplate.execute(sql,new AbstractLobCreatingPreparedStatementCallback(this.lobHandler)  
   { protected void setValues(PreparedStatement ps,LobCreator lobCreator) 
          throws SQLException 
     {
	  ps.setString(1, bean.getDeviationReportNumber());
	  ps.setString(2, bean.getMaterialsName());
	  lobCreator.setBlobAsBytes(ps, 3, bean.getDeviationReportAttachment());
						
     }
					
   });
jdbcTemplate.query(sql, new AbstractLobStreamingResultSetExtractor() {
	protected void streamData(ResultSet rs) throws SQLException,IOException 
		{
			reportBean.setId(rs.getLong("ID"));				
			reportBean.setDeviationReportAttachment(lobHandler
						.getBlobAsBytes(rs, 9));
			}
		}, params);
private byte[] InputStreamToByte(InputStream is) throws IOException {
   ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
   int ch;
   while ((ch = is.read()) != -1) {
    bytestream.write(ch);
   }
   byte imgdata[] = bytestream.toByteArray();
   bytestream.close();
   return imgdata;
  }
<action name="download" class="com.cnpc.action.MaterialReceiveAction" >
			<result name="success" type="stream">
				<param name="contentType">application/msword</param>
				<param name="inputName">inputStream</param>
				<param name="contentDisposition">attachment;filename="${exportFilename}"</param>
				<param name="bufferSize">4096</param>
			</result>
		</action>	
/**
	 * 获取下载文件名 中文名
	 * @return
	 */
	public String getExportFilename() 
	{
		try {
			return new String(this.exportFilename.getBytes(), "ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return "default";
		}
	}
	public void setExportFilename(String exportFilename) {
		this.exportFilename = exportFilename;
	}