swagger同时传递实体类型,List+Multipart文件的解决方法

  • 1.不加Multipart文件的正确传输方法
  @ApiImplicitParams({

            @ApiImplicitParam(type = "query",name = "name",value = "角色名",required = true),
            @ApiImplicitParam(type = "query", name = "remark",value = "角色备注",required = true),
            @ApiImplicitParam(type = "query", name = "createBy",value = "创建者",required = true),
    })
    @PostMapping("/register")
    public HttpResult upload(SysRole sysRole, @RequestBody List<Long> menus){
  • 2.不加List文件的正确传输方法
   @ApiImplicitParams({
            @ApiImplicitParam(type = "query",name = "name",value = "机构名",required = true),
            @ApiImplicitParam(type = "query",name = "parentId",value = "上级机构ID,一级机构为0",required = true),
            @ApiImplicitParam(type = "query",name = "createBy",value = "创建人",required = true)

    })
    @PostMapping("/register")
    public HttpResult upload(SysDept sysDept, @ApiParam("uploadFile")MultipartFile uploadFile) throws FileNotFoundException {
  • 3.同时添加List以及Multipart文件的正确传输方法:放弃实体类自动映射
   @ApiImplicitParams({
            @ApiImplicitParam(type = "query", name = "name",value = "用户名",required = true),
            @ApiImplicitParam(type = "query", name = "password",value = "密码",required = true),
            @ApiImplicitParam(type = "query", name = "deptId",value = "所属方向ID",required = true),
            @ApiImplicitParam(type = "query", name = "grade",value = "年级,比如2018",required = true),
            @ApiImplicitParam(type = "query", name = "email",value = "邮箱,确保格式正确",required = true),
            @ApiImplicitParam(type = "query", name = "mobile",value = "手机,确保格式正确",required = true),
           // @ApiImplicitParam(name = "uploadFile",value = "上传文件",dataType = "File",paramType = "form"),
//           @ApiImplicitParam(name = "roleList", value = "角色列表",dataType = "List", paramType = "body")
            //@ApiImplicitParam(type = "query", name = "createBy",value = "创建者",required = true),
            //@ApiImplicitParam(type = "query", name = "createTime",value = "创建时间",required = true)
    })
    @PostMapping("/register")
    //@PreAuthorize("hasAuthority('ROLE_USER')")
    public HttpResult register(String name, String password, Long deptId, String grade, String email, String mobile, @RequestParam List<Long> roleList, MultipartFile uploadFile  ) throws FileNotFoundException {
        //MultipartFile uploadFile = null;

这个真的是折磨了我一下午,最后还是不能偷懒,只能放弃映射,一个个的写参数,最后在方法中新建bean

你可能感兴趣的:(swagger同时传递实体类型,List+Multipart文件的解决方法)