<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • springboot集成swagger的步驟是什么

            這篇文章主要介紹“springboot集成swagger的步驟是什么”,在日常操作中,相信很多人在springboot集成swagger的步驟是什么問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”springboot集成swagger的步驟是什么”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

            成都創(chuàng)新互聯(lián)是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、做網(wǎng)站,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。十余年品質(zhì),值得信賴!

                第一步:maven導(dǎo)入Swagger如下:

                

             <!-- 添加使用swagger的依賴包 --><dependency>
                 <groupId>io.springfox</groupId>
                 <artifactId>springfox-swagger2</artifactId>
                 <version>2.2.2</version>
            </dependency>
            <!-- 添加使用swagger的依賴包 -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.2.2</version>
            </dependency>

            第二步:創(chuàng)建Swagger2配置類,如下所示:

            /**
            *
            */
            package swagger.config;

            import org.springframework.context.annotation.Bean;
            import org.springframework.context.annotation.Configuration;

            import springfox.documentation.builders.ApiInfoBuilder;
            import springfox.documentation.builders.PathSelectors;
            import springfox.documentation.builders.RequestHandlerSelectors;
            import springfox.documentation.service.ApiInfo;
            import springfox.documentation.spi.DocumentationType;
            import springfox.documentation.spring.web.plugins.Docket;
            import springfox.documentation.swagger2.annotations.EnableSwagger2;

            /**
            * @author ignore1992
            *
            */
            @Configuration
            @EnableSwagger2
            public class SwaggerConfig
            {
            @Bean
            public Docket createDocket()
            {
            return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(createApiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("swagger.api.controller"))
            .paths(PathSelectors.any())
            .build();
            }

            private ApiInfo createApiInfo()
            {
            return new ApiInfoBuilder()
            .title("springboot使用swagger2")
            .description("生成對應(yīng)接口文檔")
            .termsOfServiceUrl("https://blog.csdn.net/ignorewho")
            .contact("ignore1992")
            .version("1.0")
            .build();
            }
            }

            第三步:這樣就可以使用swagger提供的注解,來完成描述,調(diào)用,生成等功能

            常用注解如下:

            @Api : 用在類上,說明該類的主要作用。

            @ApiOperation:用在方法上,給API增加方法說明。

            @ApiImplicitParams : 用在方法上,包含一組參數(shù)說明。

            @ApiImplicitParam:用來注解來給方法入?yún)⒃黾诱f明。

            使用案例如下:

            /**
            *
            */
            package swagger.api.controller;

            import io.swagger.annotations.ApiOperation;

            import org.springframework.web.bind.annotation.RequestMapping;
            import org.springframework.web.bind.annotation.RequestMethod;
            import org.springframework.web.bind.annotation.RestController;

            /**
            * @author ignore1992
            *
            */
            @RestController
            @RequestMapping(value = "/swaggerapi")
            public class SwaggerApiController
            {
            @ApiOperation(value = "測試swaggerapi接口方法")
            @RequestMapping(value = "/test", method = RequestMethod.GET)
            public String test()throws Exception
            {
            return "swaggerapi 測試";
            }
            }

            到此,關(guān)于“springboot集成swagger的步驟是什么”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

            當(dāng)前題目:springboot集成swagger的步驟是什么
            鏈接分享:http://www.jbt999.com/article22/pdpocc.html

            成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)站維護(hù)搜索引擎優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、響應(yīng)式網(wǎng)站

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

            營銷型網(wǎng)站建設(shè)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 国产夫妻自拍在线 | 天堂中文资源网 | 99视频在线免费播放 | 91亚洲视频 | 国产三级片在线观看 |