//接口
public InputStream loadInvoiceRider(String INVOICE_ID_); //实现层 @Override public InputStream loadInvoiceRider(String INVOICE_ID_) { String sql = "select RIDER_ from MP_INVOICE where INVOICE_ID_ = ?"; return mpJdbcTemplate.queryForObject(sql, new Object[] { INVOICE_ID_ }, new RowMapper<InputStream>() { public InputStream mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getBinaryStream(1); } }); }
//控制层 @RequestMapping(value = "loadInvoiceRider") public void loadInvoiceRider(String INVOICE_ID_, HttpServletRequest request, HttpServletResponse response, HttpSession session) { Map<String, Object> result = new HashMap<String, Object>(); try { getOperator(request, session); InputStream inputStream = invoiceService.loadInvoiceRider(INVOICE_ID_); response.reset(); ServletOutputStream out = response.getOutputStream(); byte[] content = new byte[65535]; int length = 0; if (inputStream != null) { while ((length = inputStream.read(content)) != -1) { out.write(content, 0, length); } } out.flush(); out.close(); log("admin", "InvoiceController.loadInvoiceRider", INVOICE_ID_, "0", null, request, session); } catch (Exception e) { logger.error(e.getMessage(), e); result.put("message", getErrorMessage(e, request)); result.put("success", false); StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); log("admin", "InvoiceController.loadInvoiceRider", INVOICE_ID_, "1", stringWriter.toString(), request, session); } }
前台直接把请求地址,放在图片的src位置
{ xtype : ‘actioncolumn‘, width : 280, dataIndex : ‘INVOICE_ID_‘, text : ‘<spring:message code="INVOICE" />‘, align : ‘center‘, renderer : function(value, metaData, record) { var id = metaData.record.id; Ext.defer(function() { Ext.create(‘Ext.Img‘, { height : 140, width : 250, src : ‘loadInvoiceRider.do?INVOICE_ID_=‘ + value, renderTo : id, listeners : { scope : this, el : { dblclick : function(e, a) { var winViewImage = Ext.create(‘Ext.Window‘, { width : 750, height : 500, maximizable : true,//窗体最大化按钮 title : ‘<spring:message code="image" />‘, layout : "fit", //窗口布局类型 modal : true, //是否模态窗口,默认为false resizable : false,//调整窗体大小 closeAction : ‘hide‘, //关闭窗体实际上是隐藏窗体并未关闭销毁此窗体对象(节约资源) plain : true,//窗体主体部分背景颜色透明 draggable : true,//充许拖动窗体 border : false, items : [ Ext.create(‘Ext.Img‘, { width : 750, height : 500, src : ‘loadInvoiceRider.do?INVOICE_ID_=‘ + value }) ] }); winViewImage.show(); } } } }) }, 50); return Ext.String.format(‘<div id="{0}"></div>‘, id); } },