问题描述
- 用Ajax请求道action中执行了方法但没有显示结果怎么回事
-
Ajax中
//导出方法
function exportGo(url,params,grid) {$.messager.confirm('提示','您正要导出此项 !<br />请确定继续?',function(r){ if(r){ doAjax3("", url, grid, params, ""); } }); } function doAjax3(form,url,grid,param,msg){ $.ajax({ url: url, type: 'POST', cache: false, async: false, contentType:"application/json", // dataType : 'json', data: param, success: function(data, textStatus, jqXHR) { alert(data); if (!isNull(grid)) { grid.load({page:1}); } if(!isNull(form)){ form.resetForm(); } }, error:function(msg,textStatus, errorThrown) { alert(errorThrown); alert("网络错误或者处理异常,请重试或者联系管理员处理!错误信息:" + msg.responseText); } }); }
action中
/**
* 导出model的xml文件
*/
@RequestMapping(value = "export/{modelId}")
@OperatingLog(function="导出文件")
public void export(@PathVariable("modelId") String modelId,
HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService
.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); IOUtils.copy(in, response.getOutputStream()); String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml"; response.setHeader("Content-Disposition", "attachment; filename=" + filename); response.flushBuffer(); } catch (Exception e) { log.error("导出model的xml文件失败:modelId={}", modelId, e); } }
时间: 2024-08-31 18:08:34