业务背景:实现一个用药人的增加功能,用药人信息中包含附件。如题所示,主要讨论easyui上传的实现。
jsp页面代码(弹出框),一个简单的增加页面

   div id=addMedicationDlg class=easyui-window closed=true title= iconCls=icon-add style=width350px; height390px;text-aligncenter; background #fafafa;
div class=easyui-layout fit=true
div region=center border=false style=background#fff;border1px solid #ccc;padding-left 20px;
input type=hidden id=mid name=mid
form id=addMedicationForm method=POST
input type=hidden id=sex
table border=0 class=queryTable style=margin-bottom 0px tr
td class=queryTitle附件:td
td class=queryContent
input class=inputText type=text id=urlkeywords!-- 放入的是附件路径--
input type=hidden id=goodsNo name=goodsNo !-- 附件列表 --
input type=hidden class=inputText id=swfText
span id=keyWordImportBtnspan!--上传按钮--
td
td
<!--显示进度条-->
div id=fsUploadProgressdiv
div id=divStatus style=display none;div
input id=btnCancel type=buttondisabled=disabled style=display none
td
tr
table
table border=0 class=queryTable style=margin-bottom 0px id=fileIdTlb
tbody
tbody
table
form
div
div region=south border=false style=text-aligncenter;height30px;line-height30px;
a class=easyui-linkbutton iconCls=icon-ok href=javascriptvoid(0) onclick=doPostData()确定a
a class=easyui-linkbutton iconCls=icon-cancel href=javascriptvoid(0) onclick=cancelPostData('addMedicationDlg')取消a
div
div
div

js文件代码

 /**
* 打开修改&增加用药人窗口
*/
function doModifyMedication (mid){
//弹出修改&增加用药人窗口
$('#addMedicationDlg').window({
title '修改用药人',
iconCls 'icon-edit',
width750,
height550,
left250,
modal true,
shadow true,
collapsible false,
minimizable false,
maximizable false
});
$(#addMedicationDlg).show();
$('#addMedicationDlg').window('move',{top20});
$('#addMedicationDlg').window('open');
//这一步很关键,初始化上传操作
initSWFUpload({
upload_url appPath + pagequeryMedicationkeyWordImport+generateMixed(6),
post_params{},
button_placeholder_id keyWordImportBtn,
upload_start_handler uploadStartFn,
upload_success_handler importOk,
file_types .png;.jpg;.gif,
debugfalse,
custom_settings {
progressTarget fsUploadProgress,
cancelButtonId btnCancel
}
});
}
/**
*保存提交
*/
function doPostData(){
//序列化表单
var userinfo = $('#addMedicationForm').serialize();
doAjax({
urlappPath + 'pagequeryMedicationaddMedication'+ memberId,
type'POST',
datauserinfo,
successfunction(data){
if(data ==true){
$.messager.alert('提示信息','保存成功','info');
$('#selectMedicineManDlg').window('close');
cancelPostData('addMedicationDlg');
lookMedication(memberId);
}else{
$.messager.alert('提示信息','抱歉,操作未能完成,'+data,'error');
}
},
errorfunction(XMLHttpRequest, textStatus, errorThrown){
$.messager.alert('提示信息','抱歉,操作未能完成,'+textStatus,'error');
}
});
}
/**
*取消提交
*@param dlg
*/
function cancelPostData(dlg){
$('#'+dlg).window('close');
}

后台java代码

      /**
* 保存文件(在文件初始化的时候执行)
*
* @param request
* @param response
* @param uploadFile
* @throws Exception
*/
@RequestMapping(value = "/keyWordImport")
public Object keyWordImport(HttpServletRequest request,
HttpServletResponse response,
@RequestParam("uploadFile") MultipartFile f) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HashMap<String, Object> map = new HashMap<String, Object>();
String type = "" ;
String splitKey = ""; //---设置字符集
try {
request.setCharacterEncoding("utf-8");
} catch (Exception e) {
e.printStackTrace();
}
response.setCharacterEncoding("utf-8"); if (null != request.getParameter("splitKey")){
splitKey = request.getParameter("splitKey");
} //---获取文件名称、文件后缀名称以及生成新名称
String oldFileName = f.getOriginalFilename();
if(null!=oldFileName && oldFileName.contains(".")){
type = oldFileName.substring(oldFileName.lastIndexOf(".")).toLowerCase();
}
String newFileName =oldFileName.substring(0,oldFileName.lastIndexOf("."))+String.valueOf(System.currentTimeMillis())+type;
try {
// ---获取文件保存目录名称 String saveFolder = request.getSession().getServletContext()
.getRealPath("upload")
+ "/" + "otcFolder"; String newFileNamePath = "/upload/otcFolder/"+ newFileName;
map.put("newFileName", newFileNamePath); // ---上传
Map<String, Object> res = uploadService.doUpload(saveFolder,
f.getBytes(), newFileName, splitKey, "otcFolder");
// ---返回值
if (0 == (Integer) res.get("error")) {
request.setAttribute("res", "success");
response.getWriter().write(org.json.simple.JSONObject.toJSONString(map));
} else {
request.setAttribute("res",
"err : " + (String) res.get("message"));
}
} catch (Exception e) {
request.setAttribute("res", "err : " + e.getMessage());
logger.error("upload failed in action " + e.getMessage());
}
return null;
}
//保存用药人新增数据
@RequestMapping(value="/addMedication/{memberId}")
@ResponseBody
public String addMedication (HttpServletRequest request ,@PathVariable Long memberId,Medication medication) throws Exception {
String fileList = medication.getGoodsNo();
String temps [] =fileList.split(",");
List<MedicationMemberFile> list =new ArrayList<MedicationMemberFile>();
for (int i = 0 ;i<temps.length ; i++){
MedicationMemberFile medicationMemberFile = new MedicationMemberFile();
if (temps[i].trim().length() >0 || temps[i].trim() != null){
medicationMemberFile.setFilePath(temps[i]);
list.add(medicationMemberFile);
}
}
medication.setMedicationMemberFile(list);
medication.setMemberId(memberId);
String result ="";
String resultDataRecord = SOAJsonClient.sendMsgToOtc(OtcJsonCodeRelation.JsonAssignedDetailsTasksService_setAddMedication,JSON.toJSONString(medication) );
JSONObject objectRecord = JSONObject.fromObject(resultDataRecord);
String objectstate=String.valueOf(objectRecord.get("state"));
if(objectstate.trim().length() >0 && objectstate.equals("0")){
result ="true";
}
return result;
}

最新文章

  1. 我和linux的第二十二天
  2. 【翻译】Kinect v2程序设计(C++-) AudioBeam篇
  3. nginx、fastCGI、php-fpm关系梳理(转载 http://blog.sina.com.cn/s/blog_6df9fbe30102v57y.html)
  4. 使用myeclipse建立maven项目(重要)
  5. phpexcelreader超级简单使用
  6. c语言main函数的参数argc,argv说明
  7. python登陆教务管理系统
  8. 基于visual Studio2013解决面试题之1101差值最小
  9. VS2003与Win7的兼容性问题
  10. BZOJ 2244: [SDOI2011]拦截导弹 [CDQ分治 树状数组]
  11. npm修改淘宝原
  12. Civil 3D 二次开发 创建AutoCAD对象—— 00 ——
  13. Python文学家为Python写的一首词?(附中英文版)
  14. 在centos7虚拟机上挂载镜像,并设置yum源(包括遇到的问题)
  15. 2019.3.28&amp;2019.3.30考试
  16. Codeforces 219D - Choosing Capital for Treeland(树形dp)
  17. cpio解压initramfs.img
  18. Twisted框架
  19. 彻底删除vscode及安装的插件和个人配置信息
  20. javascript中setInterval制作跑马灯的效果

热门文章

  1. grep 命令使用指南
  2. 第八章 JVM内存管理
  3. kali下安装go环境
  4. springboot成神之——mybatis和mybatis-generator
  5. 工程添加EF框架的方法
  6. DRF之解析器组件及序列化组件
  7. HttpURLConnection连接网页和获取数据的使用实例
  8. 在VS13上编译通过的代码放在12上编译-错误:l __dtoui3 referenced in function _event_debug_map_HT_GROW
  9. quartz在web.xml的配置
  10. HDR