zoukankan      html  css  js  c++  java
  • java 用若依框架从app添加数据和图片

    @PostMapping("/addfile")
    @ResponseBody
    public AjaxResult addSave(@RequestParam(value = "file") MultipartFile[] files, @RequestParam(value = "json") String json)
    {
    String code = "";
    String msg = "";
    String url = "";
    AnjianLvhua anjianLvhua = JSON.parseObject(json, AnjianLvhua.class);
    int a=anjianLvhuaService.insertAnjianLvhua(anjianLvhua);
    if(files.length>0) {
    try {
    for(MultipartFile file : files) {
    AnjianLvhuaFile weifaImgFile = new AnjianLvhuaFile();
    // 上传文件路径
    String filePath = RuoYiConfig.getUploadPath();
    // 上传并返回新文件名称
    String fileName = null;
    try {
    fileName = FileUploadUtils.upload(filePath, file);
    } catch (IOException e) {
    e.printStackTrace();
    }
    url = serverConfig.getUrl() + fileName;
    //上传图片成功以后,开始保存图片地址到对应的项中
    weifaImgFile.setWeifaId(anjianLvhua.getLvhuaId());
    weifaImgFile.setFilePath(url);
    weifaImgFile.setFileName(fileName);
    weifaImgFile.setFileTime(new Date());
    int flag = anjianLvhuaFileService.insertAnjianLvhuaFile(weifaImgFile);
    }

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    } catch (Exception e) {
    e.printStackTrace();
    }

    }
    if(a>0){
    msg = "提交成功";

    code = AjaxResult.SUCCESS_STATUS;
    }else{
    msg = "提交失败";
    code = AjaxResult.ERROR_STATUS;
    }
    return new AjaxResult(code, msg, anjianLvhua);
    }
  • 相关阅读:
    平方分割poj2104K-th Number
    平方分割poj2104K-th Number
    GIT学习之路第五天 分支管理
    GIT学习之路第五天 分支管理
    daily_journal_2 神奇的一天
    daily_journal_2 神奇的一天
    51nod1264 线段相交
    51nod1264 线段相交
    51nod1265判断四点共面
    51nod1265判断四点共面
  • 原文地址:https://www.cnblogs.com/fzc521/p/13515729.html
Copyright © 2011-2022 走看看