使用Postman对@RequestPart和HttpServletRequest组合传参方式

使用Postman对@RequestPart和HttpServletRequest组合传参方式

方法代码如下:

java 复制代码
    /**
     * 发布
     */
    @ApiOperation("发布")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "req", value = "json格式", dataType = "Map", dataTypeClass = Map.class),
            @ApiImplicitParam(name = "file", value = "文件", dataType = "File", dataTypeClass = File.class)
    })
    @PostMapping("/publish")
    public AjaxResult publish(@Validated @RequestPart("req") BizDemandInfo entity, HttpServletRequest request) throws IOException {
        List<MultipartFile> fileList = ((MultipartHttpServletRequest) request).getFiles("file");
        // 限制上传文件大小,单位是字节
        final long MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
        // 限制上传文件的数量
        final int MAX_FILES = 5;
        List<BizDemandAttachment> attachmentList = new ArrayList<>();
        if (!fileList.isEmpty()) {
            //上传文件数不能大于5
            if (fileList.size() > MAX_FILES) {
                log.error("上传文件数不能大于5");
                return AjaxResult.error("上传文件数不能大于5");
            }
            for (MultipartFile file : fileList) {
                //每个文件不能大于10M
                if (file.getSize() > MAX_FILE_SIZE) {
                    log.error("每个文件不能大于10M");
                    return AjaxResult.error("每个文件不能大于10M");
                }
                String url = FileUploadUtils.uploadMinio(Constants.MINIO_BUCKET_NAME_DEMAND, file);
                String fileName = file.getOriginalFilename();
                BizDemandAttachment attachment = new BizDemandAttachment();
                attachment.setAttachmentName(fileName);
                attachment.setAttachmentUrl(url);
                attachmentList.add(attachment);
            }
        }
        entity.setBizDemandAttachmentList(attachmentList);
        String createBy = getUsername();
        entity.setCreateBy(createBy);
        String id = service.insert(entity);
        return StringUtils.isNoneBlank(id) ? AjaxResult.success(id) : AjaxResult.error();
    }

想使用postman对entity和request参数传参,应该怎么传呢?

传参方法:

直接上图片

因为参数entity是@RequestPart("req") BizDemandInfo entity,所以名称得填req。最重要的是Content-Type要填application/json

里面的内容直接填json串就可以了。

相关推荐
一 乐5 小时前
物流信息管理|基于springboot + vue物流信息管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·物流信息管理系统
希望永不加班6 小时前
SpringBoot 自动配置类加载顺序与优先级
java·spring boot·后端·spring·mybatis
希望永不加班9 小时前
SpringBoot 事件机制:ApplicationEvent 与监听器
java·开发语言·spring boot·后端·spring
却话巴山夜雨时i9 小时前
互联网大厂Java面试实录:技术栈解析与场景剖析
java·大数据·spring boot·spring cloud·微服务·ai·面试
测试19989 小时前
postman接口测试详解
自动化测试·软件测试·python·测试工具·测试用例·接口测试·postman
gelald10 小时前
SpringBoot - 配置加载
spring boot·后端·spring
海南java第二人11 小时前
Spring Boot + Cursor 实战:从零到一搭建一个生产级用户中心
spring boot·ai coding
昵称为空C11 小时前
在复杂SpringBoot项目中基于hutool实现临时添加多数据源案例
spring boot·后端
计算机学姐12 小时前
基于SpringBoot的房屋交易系统
java·vue.js·spring boot·后端·spring·intellij-idea·mybatis