使用Swagger2構建文檔內容

來源:互聯網
上載者:User
使用Swagger2構建文檔內容
import io.swagger.annotations.*;import lombok.AllArgsConstructor;import lombok.Data;import lombok.NoArgsConstructor;import lombok.experimental.Accessors;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * @author Created by 譚健 on 2018/4/13 0013. 星期五. 9:30. * © All Rights Reserved. *//** * 用在類上,說明類的用途 */@Api(tags = {"swagger2控制器"})@RequestMapping("/swagger2")@RestControllerpublic class Swagger2Controller {    /**     * 用在方法上,說明方法的用途     */    @ApiOperation(value = "get方法", notes = "get用的")    /**     * 用在方法上,說明參數的用途     */    @ApiImplicitParams({            @ApiImplicitParam(name = "s", value = "入參", required = true, defaultValue = "ok")    })    /**     * 用在方法上,說明響應的方式     */    @ApiResponses({            @ApiResponse(code = 200, message = "請求成功", response = Exception.class),            @ApiResponse(code = 404, message = "請求路徑錯誤", response = Exception.class)    })    @GetMapping("/get")    public String get(String s) {        return s;    }    @PostMapping("/post")    public SwaggerClass post(){        return new SwaggerClass().setName("文檔").setSize(5000).setDescribe("自動產生的文檔");    }    /**     * 用在響應類上,說明響應類     */    @ApiModel(description = "返回的響應類")    @Data    @NoArgsConstructor    @AllArgsConstructor    @Accessors(chain = true)    public class SwaggerClass{        @ApiModelProperty(value = "名稱")        private String name;        @ApiModelProperty(value = "大小")        private int size;        @ApiModelProperty(value = "描述")        private String describe;    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.