使用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串就可以了。

相关推荐
华子w90892585940 分钟前
基于 SpringBoot+Vue.js+ElementUI 的 “花开富贵“ 花园管理系统设计与实现7000字论文
vue.js·spring boot·elementui
小时候的阳光1 小时前
SpringBoot3 spring.factories 自动配置功能不生效?
spring boot·spring·失效·factories·imports
大只鹅2 小时前
Springboot3整合ehcache3缓存--XML配置和编程式配置
spring boot·缓存
执笔诉情殇〆3 小时前
springboot集成达梦数据库,取消MySQL数据库,解决问题和冲突
数据库·spring boot·mysql·达梦
hdsoft_huge3 小时前
Spring Boot 高并发框架实现方案:数字城市的奇妙之旅
java·spring boot·后端
gjh12085 小时前
Easy-excel监听器中对批量上传的工单做错误收集
java·spring boot
考虑考虑6 小时前
使用jpa中的group by返回一个数组对象
spring boot·后端·spring
十一0829936 小时前
【PDF-XSS攻击】springboot项目-上传文件-解决PDF文件XSS攻击
spring boot·pdf·xss
风象南7 小时前
Spring Shell命令行工具开发实战
java·spring boot·后端
小小霸王龙!8 小时前
互联网大厂Java面试实录:Spring Boot与微服务在电商场景中的应用
java·spring boot·redis·微服务·电商