uploadify 提交表单 照片已经提交上去了~但是数据库里面没有文件名~应该怎么做~求解

漫步东海湾 发布于 2015/12/22 15:05
阅读 535
收藏 0


controller层

@RequestMapping(value="/upload.html")  
@ResponseBody
    public Object uploadFile(HttpServletResponse response,Model model,
    HttpServletRequest request,@RequestParam(value="image", required=false) MultipartFile image) throws IOException{  
        byte[] bytes = image.getBytes();  
        System.out.println(image.getOriginalFilename());  
        String uploadDir = request.getRealPath("/")+"upload";  
        File dirPath = new File(uploadDir);  
        if (!dirPath.exists()) {  
            dirPath.mkdirs();  
        }  
        String sep = System.getProperty("file.separator");  
        File uploadedFile = new File(uploadDir + sep  
                + image.getOriginalFilename());  
        FileCopyUtils.copy(bytes, uploadedFile);  
        System.err.println(uploadedFile.getPath());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msg", true);
        jsonObject.put("filepath", "upload/"+image.getOriginalFilename());
        return jsonObject.toJSONString();
        
        
    }  

@RequestMapping(value="/add.html")
public String toAdd(String image,Long id,String title,String content,String extend,Integer plat,
String pn,Integer bannerType,Integer childType,String url,Long addtime,HttpServletRequest request,Model model) throws IOException{
 
//model.addAttribute("fileUrl", request.getContextPath()+"/upload/"+fileName);
if(id!=null&&id!=0){
AppBanner appBanner=appBannerService.get(id);
appBanner.setBannerType(bannerType);
appBanner.setChildType(childType);
appBanner.setContent(content);
appBanner.setExtend(extend);
appBanner.setImage(image);
appBanner.setPlat(plat);
appBanner.setPn(pn);
appBanner.setTitle(title);
appBanner.setUrl(url);
if(id!=null||id!=0){
appBannerService.update(appBanner);
}
 
}else{
addtime = System.currentTimeMillis();
AppBanner appBanner=new AppBanner();
appBanner.setBannerType(bannerType);
appBanner.setChildType(childType);
appBanner.setContent(content);
appBanner.setExtend(extend);
appBanner.setPlat(plat);
appBanner.setImage(image);
appBanner.setAddtime(addtime);
appBanner.setPn(pn);
appBanner.setTitle(title);
appBanner.setUrl(url);
if(id==null||id==0){
appBannerService.save(appBanner);
}



}
return "redirect:/appBanner/index.html";
}


   js  :


 $(function () {
         $("#image").uploadify({
             'swf': '${ctx}resources/css/uploadify.swf',
             'uploader': '${ctx}appBanner/upload.html',
             'buttonText': '上传图片',
             'fileTypeDesc': 'Image Files',
             'fileTypeExts': '*.gif; *.jpg; *.png',
             'auto': true,
             'multi': false,
             'fileObjName'   : 'image',
             'onComplete': function (event, queueId, fileObj, response, data) {
            alert("文件:" + fileObj.name + "上传成功"+data.filepath);
             }
         });
     }); 

body:

  
        <input type="file" name="image" id="image" />
        <p>
            <a href="javascript:$('#image').uploadify('upload','*')">上传</a>| 
            <a href="javascript:$('#image').uploadify('cancel')">取消上传</a>
        </p>
   

        
  
加载中
返回顶部
顶部