我正在使用Spring MVC,这是我的方法:

/**
* Upload single file using Spring Controller.
*/
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<GenericResponseVO<? extends IServiceVO>> uploadFileHandler(
            @RequestParam("name") String name,
            @RequestParam("file") MultipartFile file,
            HttpServletRequest request,
            HttpServletResponse response) {

    if (!file.isEmpty()) {
        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            String rootPath = System.getProperty("catalina.home");
            File dir = new File(rootPath + File.separator + "tmpFiles");
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator + name);
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();

            System.out.println("Server File Location=" + serverFile.getAbsolutePath());

            return null;
        } catch (Exception e) {
            return null;
        }
    }
}

我需要在邮递员和文件中传递会话id。我该怎么做呢?


当前回答

在看到所有的答案后,我感到困惑,我找不到任何合适的截图来带来内容类型列。过了一段时间,我自己找到了它。希望这能帮助到像我这样的人。

以下是步骤:

点击邮递员的红色标记区域。 现在检查绿色标记的选项(Content Type)。 现在改变搜索内容类型,在黄色标记的区域。

在我的例子中:

Invoice_id_ls (key)包含json数据。 文档包含文件数据。 Placed_amount包含普通文本字符串。

其他回答

请按照下图从上到下的步骤进行操作。

在第三步,你会发现下拉类型选择如下图所示

对于每个可以设置Content-Type的表单数据键,右侧有一个邮递员按钮来添加Content-Type列,并且您不必从控制器中的字符串解析json。

您可以同时发送Image和可选/必选参数。

在postman中,有Params标签。

首先,设置post in方法和填充链接API

然后选择Body -> form-data ->输入你的参数名(根据你的代码文件)

也许你可以这样做: