postman 请求上传文件,post请求携带文件,以及对应postMapping 处接收写法

一、postman 处表单携带文件的方式

先要修改content-type

必须改,否则不支持

java 复制代码
Content-Type
multipart/form-data

Body 表单处

二、JavaWeb @PostMapping 处接收的写法

不要带 @RequestBody

不要带 @RequestBody

不要带 @RequestBody

java 复制代码
	@PostMapping(value = "/importXxxxx")
    public Response importXxxxxx(XxxxxxxRequest xxx) throws Exception {
    ..........
    }

XxxxxxxRequest 中类似如下
public class XxxxxxxRequest {

    private Long taskId;

    private MultipartFile file;

	.......
	.......
	.......
}

是的,这样就可以拿到

当然 同时在定义的类外面写也可以获取到 例如

java 复制代码
    @PostMapping(value = "/importXxxxx")
    public Response importXxxxxx(XxxxxxxRequest xxx,
                                  @RequestParam(value = "file") MultipartFile file) {
......
}

此时 外面的file 也是被赋值了的,当然 上面postman 还是没有变化的 还是一个表单

相关推荐
吃饱了想撑死1 天前
Postman四种请求教程
测试工具·postman
大白曾是少年2 天前
基于Postman进行http的请求和响应
测试工具·http·postman
努力的小Qin5 天前
oneapi本地部署接口测试(curl命令方式+postman方式)
测试工具·postman·oneapi
友莘居士5 天前
本地使用postman调试mcp接口
测试工具·postman·sse·mcp
绿色果酱10 天前
Apipost:离线可用+AI全栈覆盖,国产API开发协作工具新标杆
postman·ai功能·apipost·apipost离线·apipost ai·ai能力·apipost操作
alien爱吃蛋挞10 天前
Postman
测试工具·postman
Feng.Lee11 天前
接口测试Postman工具高级使用技巧
功能测试·测试工具·lua·postman·可用性测试
CtrlCV 攻城狮15 天前
接口测试时如何上传文件(图片、安装包等)
python·postman
Feng.Lee16 天前
聊聊接口测试Postman环境与变量的深度应用
测试工具·lua·postman·可用性测试
哈哈孝子17 天前
Postman接口
测试工具·postman