• 5.2团队冲刺05


    今天做了文件下载

    下面是代码,下载还是根据url的定位

    public class DownloadAndUploadController {
    @Autowired
    private Upload upload;
    @Autowired
    private ImgMapper imgService;
    @RequestMapping("/UploadImg")
    @ResponseBody
    public String UploadImg(MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException {
    upload.uploadOne(staticConfig.UserMail,file);
    return staticMsg.successfulUpload;
    }

    @RequestMapping("/DownloadImg")
    @ResponseBody
    public byte[] downloadImg(String fileName) throws IOException {
    ImgObject imgObject=imgService.getImg(fileName);
    return FileUtil.readFileStreamByBytes(ImageCompression.ImgCompression(imgObject));
    }

    @RequestMapping("/DownloadRealImg")
    @ResponseBody
    public byte[] downloadRealImg(String fileName) throws IOException {
    ImgObject imgObject=imgService.getImg(fileName);
    return FileUtil.readFileByBytes(imgObject.getImgPath()+imgObject.getImgId()+imgObject.getImgName().substring(imgObject.getImgName().lastIndexOf(".")));
    }

    @RequestMapping("/getImgList")
    @ResponseBody
    public String getImgList(String class2){

    JSONArray jsonArray=new JSONArray();
    String str2="#";
    if(class2==null){
    System.out.println("class2==null");
    List<ImgObject> imgObjects=imgService.getUserAllImg(staticConfig.UserMail);
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    if(!str2.equals(imgObject.getImgPath().substring(str.indexOf("\")+ 1,str.indexOf("-")).substring(str.lastIndexOf("m")+2))){
    str2=str.substring(str.indexOf("\")+ 1,str.indexOf("-")).substring(str.lastIndexOf("m")+2);
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }

    }
    return jsonArray.toJSONString();
    }else {
    System.out.println("class2="+class2);
    List<ImgObject> imgObjects=imgService.getUserImgByFile(staticConfig.UserMail,class2);
    if (class2.contains("-"))
    {
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    str=str.substring(str.indexOf(class2));
    str=str.substring(str.indexOf("\")+1);
    str=str.substring(0,str.indexOf("\"));
    System.out.println(str);
    if (!str2.equals(str)){
    str2=str;
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }
    }

    }
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    //str=str.substring(str.indexOf("-")+1).substring(0,str.indexOf("\"));
    str=str.substring(str.indexOf(class2));
    str=str.substring(0,str.indexOf("\"));
    System.out.println(str);
    if (!str2.equals(str)){
    str2=str;
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }
    }
    return jsonArray.toJSONString();
    }
    }
  • 相关阅读:
    关于Jquery内存的释放
    jQuery 事件 mouseleave() 方法 mouseenter() 方法
    模版方法模式
    js中return的用法
    HTTP返回码中301与302的区别
    DS介绍
    Java MySql乱码解决
    [IOS] UIViewController的parentViewController属性
    LinuxFind命令
    Linux第一课
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/14910300.html
Copyright © 2020-2023  润新知