controller 层

@Controller
@RequestMapping(value="common")
/**
 * 上传文件
 */
@RequestMapping(value = "/uploadImg", method = RequestMethod.POST)
@ResponseBody
public ResultObject moli(@RequestParam("file") MultipartFile file) throws IOException {
    //创建返回值
    ResultObject ret = new ResultObject();
    PageData pd=new PageData();

    try {
        String  ffile = DateUtil.getDays(), fileName = "";
        if (null != file && !file.isEmpty()) {
            String filePath = PathUtil.getClasspath() + Const.FILEPATHIMG + ffile;    //文件上传路径
            fileName = FileUpload.fileUp(file, filePath, this.get32UUID());             //执行上传
           // System.out.println(filePath);
            String name=file.getOriginalFilename();
            int size=(int)file.getSize();
            //System.out.println("文件名:"+name+","+"大小:"+size);
            pd.put("resource_id",UuidUtil.get32UUID());
            pd.put("file_name",name);
            pd.put(size,size);
        }else{
            System.out.println("上传失败");
        }
        //HashMap<String, String> result = FileUploadByHttp.uploadFile(file);

        ret.setSuccess(1);
        ret.setEntity(pd);
    } catch (Exception e) {
        ret.setMsg(e.getMessage());
        ret.setSuccess(0);
        logger.error(e.getMessage(), e);
    }
    return ret;
}

根据ret就可以返回你想要的东西,文件的名称,文件的大小,文件的id,

当发送请求的时候可以直接写,例如:

所以你想要的参数都可以传过来啦

文件上传,接口返回主键id

不传参数的时候就是这种写法

文件上传,接口返回主键id

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2021-05-25
  • 2022-12-23
  • 2021-04-09
  • 2022-02-05
  • 2021-07-28
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2022-02-01
  • 2021-12-02
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案