zoukankan      html  css  js  c++  java
  • swagger 文件上传以及requestbody参数传递

    swagger用来做普通的API测试很方便,在实际开发过程中,经常会有文件上传,或者通过reuestbody传递数据等方式. 这个时候swagger的配置就有一些特殊了

    swagger requestbody的配置方式

    @ApiOperation(value = "测试requestBody", notes = "测试requestBody")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name="userId", value="用户id", dataTypeClass = Integer.class, required = true),
            @ApiImplicitParam(paramType="body", name = "body",dataType = "string", example = "", required = false)
    })
    @PostMapping(value="/command",produces = {"application/json;charset=UTF-8"})
    public String getHttpInfo(HttpServletRequest request, Integer userId) throws IOException {
        InputStream in = request.getInputStream();
        String requestParams = IOUtils.toString(in);
        // TODO. LOGIC
        return requestParams;
    }

    swagger 文件上传配置方式

    @ApiOperation(value = "测试swagger3上传", notes = "测试swagger3上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", paramType="form", value = "临时文件", dataType="file", required = true),
            @ApiImplicitParam(name="userId", value="用户ID", dataTypeClass = Integer.class, required = true)
    })
    @PostMapping(value = "/update_avatar")
    public String updateAvatar(Integer userId, @RequestPart("file") MultipartFile file) throws Exception {
        // TOTO. LOGIC.
        return file.getName();
    }

    参考资料

  • 相关阅读:
    微信公众平台开发(6) 微信退款接口
    shiro 认证和授权原理
    Shiro架构
    微信公众平台开发(5) 微信客服消息接口
    微信公众平台开发(4) 微信模板消息接口
    微信公众平台开发(3) 企业付款
    微信公众平台开发(1) 通用的工具类CommonUtil
    spring 源码构建
    springMvc配置拦截器无效
    IIdea使用CXF开发WebService
  • 原文地址:https://www.cnblogs.com/exmyth/p/15470927.html
Copyright © 2011-2022 走看看