上传(jsp):
<form action="caseKnowledge/${msg }.do" name="ckForm" id="ckForm" method="post" enctype="multipart/form-data"> <input type="hidden" name="ck_belong" value="${CK_BELONG }"/> <input type="hidden" name="ck_id" id="ck_id" value="${pd.CK_ID }"/> <table id="table_report" class="table table-striped table-bordered table-hover"> <c:if test="${fx != 'head'}"> <tr> <td style="width:79px;text-align: right;padding-top: 13px;">类型:</td> <td id="tp_ids"> <select class="chosen-select form-control" name="tp_id" id="tp_id" data-placeholder="请选择类型" style="vertical-align:top;" style="width:98%;" > <option value=""></option> <c:forEach items="${tpList}" var="tp"> <option value="${tp.TP_ID }" <c:if test="${tp.TP_ID == pd.TP_ID }">selected</c:if>>${tp.TP_NAME }</option> </c:forEach> </select> </td> </tr> </c:if> <tr> <td style="width:79px;text-align: right;padding-top: 13px;">标题:</td> <td><input type="text" name="ck_title" id="ck_title" value="${pd.CK_TITLE }" maxlength="32" placeholder="这里输入标题" title="标题" style="width:98%;"/></td> </tr> <tr> <td style="width:79px;text-align: right;padding-top: 13px;">简介:</td> <td><input type="text" name="ck_blurb" id="ck_blurb" value="${pd.CK_BLURB }" maxlength="32" placeholder="这里输入简介" title="简介" style="width:98%;"/></td> </tr> <tr id="attach_type"> <td style="width:79px;text-align: right;padding-top: 13px;">附件类型:</td> <td> <select name="ck_attach_type" id="ck_attach_type" placeholder="附件类型" title="附件类型" style="width:98%;"> <option value="">请选择附件类型</option> <option value="0">图片</option> <option value="1">视频</option> <option value="2">文档</option> </select> </td> </tr> <tr id="attach_path"> <td style="width:79px;text-align: right;padding-top: 13px;">附件:</td> <td> <input type="file" name="file" id="ck_attach_path" style="width:98%;"/> </td> </tr> <tr style="display: none;"> <td style="width:79px;text-align: right;padding-top: 13px;">状态:</td> <td> <span id="ck_state"></span> <input type="radio" name="ck_state" title="状态" value="0" checked="checked">可用 <input type="radio" name="ck_state" title="状态" value="1" >不可用 </td> </tr> <tr> <td style="width:79px;text-align: right;padding-top: 13px;">备注:</td> <td><textarea name="remarks" id="remarks" title="备注" style="width:98%;">${pd.REMARKS }</textarea></td> </tr> <tr> <td style="text-align: center;" colspan="10"> <a class="btn btn-mini btn-PRimary" onclick="save();">保存</a> <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a> </td> </tr> </table></form>上传(controller):/** * 添加 * @param file * @param request * @return * @throws Exception */ @RequestMapping(value="/saveCK") public ModelAndView saveCK(@RequestParam MultipartFile file,HttpServletRequest request) throws Exception{ if(!Jurisdiction.buttonJurisdiction(ckUrl, "save")){return null;} //校验权限 ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); pd=this.getPageData(); pd.put("CK_ID", this.get32UUID()); pd.put("TP_ID", request.getParameter("tp_id")); pd.put("CK_TITLE", request.getParameter("ck_title")); pd.put("CK_BLURB", request.getParameter("ck_blurb")); pd.put("CK_ATTACH_TYPE", request.getParameter("ck_attach_type")); //图片、视频、文档的路径 String url=""; // 文件保存路径 if("0".equals(pd.getString("CK_ATTACH_TYPE"))){ //图片 url = "/images/"; }else if("1".equals(pd.getString("CK_ATTACH_TYPE"))){ //视频 url = "/video/"; }else if("2".equals(pd.getString("CK_ATTACH_TYPE"))){ //文档 url = "/document/"; } pd.put("CK_BELONG", request.getParameter("ck_belong")); //0--案例知识 1--教学素材 //获取当前登录人 Httpsession session = getRequest().getSession(); User user = (User)session.getAttribute(Const.SESSION_USER); //如果是学生则添加的时候为无 如果是老师 则显示老师name //通过用户Id获取角色Id 从而得出角色名称 pd.put("ROLE_ID", user.getROLE_ID()); if(roleService.findObjectById(pd).getString("ROLE_NAME").equals("学生")){ pd.put("USER_ID", ""); pd.put("AUDIT_TIME", "无"); pd.put("AUDIT_STATE", "2"); //还要判断 如果是学生则需要审核 如果是老师 则不需要审核 }else{ pd.put("USER_ID", user.getUSER_ID()); pd.put("AUDIT_TIME", ContractController.getTime()); pd.put("AUDIT_STATE", "0"); //还要判断 如果是学生则需要审核 如果是老师 则不需要审核 } pd.put("CK_STATE", request.getParameter("ck_state")); if("".equals(request.getParameter("remarks"))){ pd.put("REMARKS", "无"); }else{ pd.put("REMARKS", request.getParameter("remarks")); } pd.put("CREATE_BY", user.getNAME()); pd.put("CREATION_DATE", ContractController.getTime()); pd.put("LAST_UPDATE_DATE", ContractController.getTime()); pd.put("TEMP1", ""); pd.put("TEMP2", ""); pd.put("TEMP3", ""); System.out.println("pd-->"+pd); //获取文件名 String fileName = file.getOriginalFilename(); //文件扩展名 String extName = fileName.substring(fileName.lastIndexOf(".")); String newName = this.get32UUID()+extName; System.out.println("file.getOriginalFilename()"+file.getOriginalFilename()); pd.put("CK_ATTACH_PATH", "knowledge/"+url+newName); // 判断文件是否为空 if (!file.isEmpty()) { try { String filePath = request.getSession().getServletContext().getRealPath("uploadFiles/knowledge")+url+newName; System.out.println("filePath-->"+filePath); // 转存文件 file.transferTo(new File(filePath)); } catch (Exception e) { e.printStackTrace(); } } caseKnowledgeService.saveCK(pd); mv.addObject("CK_BELONG", request.getParameter("ck_belong")); mv.addObject("msg","success"); mv.setViewName("save_result"); //mv.setViewName("redirect:list.do?CK_BELONG="+request.getParameter("ck_belong")); return mv; }删除:/** * 删除 * @return * @throws Exception */ @RequestMapping(value="/deleteCK") public ModelAndView deleteCK(HttpServletRequest request) throws Exception{ if(!Jurisdiction.buttonJurisdiction(ckUrl, "del")){return null;} //校验权限 ModelAndView mv=this.getModelAndView(); PageData pd=this.getPageData(); PageData caseKnow = caseKnowledgeService.findById(pd); //System.out.println("**********"+request.getSession().getServletContext().getRealPath("uploadFiles/"+caseKnow.getString("CK_ATTACH_PATH"))); File file = new File(request.getSession().getServletContext().getRealPath("uploadFiles/"+caseKnow.getString("CK_ATTACH_PATH"))); if (!file.isDirectory()) {//如果文件没有被销毁,则删除 file.delete(); } caseKnowledgeService.deleteCK(pd); mv.addObject("msg","success"); mv.addObject("CK_BELONG", pd.getString("CK_BELONG")); mv.setViewName("save_result"); return mv; }在线预览(controller):/** * 查看附件 * @return * @throws Exception */ @RequestMapping(value="/view") public ModelAndView view(HttpServletRequest request) throws Exception{ if(!Jurisdiction.buttonJurisdiction(ckUrl, "cha")){return null;} //校验权限 ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); System.out.println("pd-->"+pd); pd=caseKnowledgeService.findById(pd); //判断路径是否存在 File file = new File(request.getSession().getServletContext().getRealPath("uploadFiles/"+pd.getString("CK_ATTACH_PATH"))); if(!file.exists()) { //如果不存在 pd.put("path", "hasnotPath"); } mv.addObject("pd", pd); mv.setViewName("knowledge/caseKnowledge/ck_view"); return mv; }在线预览(jsp):<div class="col-xs-12" style="text-align: center;"> <input type="hidden" name="ck_id" id="ck_id" value="${pd.CK_ID }"/> <c:choose> <c:when test="${pd.path != 'hasnotPath' }"> <!-- 图片 --> <c:if test="${pd.CK_ATTACH_TYPE == 0 }"> <img src="uploadFiles/${pd.CK_ATTACH_PATH}"/> </c:if> <!-- 视频 --> <c:if test="${pd.CK_ATTACH_TYPE == 1 }"> <video autoplay="autoplay" controls="controls" src="uploadFiles/${pd.CK_ATTACH_PATH}" loop="-1"></video> </c:if> <!-- 文档 --> <c:if test="${pd.CK_ATTACH_TYPE == 2 }"> <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" border="0"> <param name="_Version" value="65539"> <param name="_ExtentX" value="20108"> <param name="_ExtentY" value="10866"> <param name="_StockProps" value="0"> <param name="SRC" value="uploadFiles/${pd.CK_ATTACH_PATH}"> <object data="uploadFiles/${pd.CK_ATTACH_PATH}" type="application/pdf" width="99%" height="630" class="hiddenObjectForIE"> </object> </object> </c:if> </c:when> <c:otherwise> <div style="margin: auto; padding-top: 20px;">文件找不到了!</div> </c:otherwise> </c:choose> </div><script type="text/javascript"> $(top.hangge()); //var iw = $("img").width(); //var ih = $("img").height(); //改变图片的大小 function changeImg(){ var iw = $("img").width(); var ih = $("img").height(); if(iw <= ih){ $("img").width(630*iw/ih); $("img").height(630); }else{ $("img").width(840); $("img").height(840*ih/iw); } } $(document).ready(function(){ //图片 changeImg(); //视频 var vw = $("video").width(); var vh = $("video").height();// alert("宽:"+vw+"*****高:"+vh); $("video").width(840); // $("video").height(865*vh/vw); }); $("img").click(function(){ var iw = $("img").width(); var ih = $("img").height(); if(iw < ih){ if($("img").width() != 820){ $("img").width(820); $("img").height(820*ih/iw); }else{ $("img").width(630*iw/ih); $("img").height(630); } } });</script>
新闻热点
疑难解答