springboot2.2.2集成swagger生成api接口文档

springboot版本为2.2.2.RELEASE,jdk为1.8,swagger为2.6.1

1、修改pom文件,添加swagger依赖

 <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-mockmvc</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-staticdocs</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.58</version>
        </dependency>
        <dependency>
            <groupId>io.github.robwin</groupId>
            <artifactId>markup-document-builder</artifactId>
            <version>0.1.5</version>
        </dependency>
        <dependency>
            <groupId>io.github.robwin</groupId>
            <artifactId>swagger2markup</artifactId>
            <version>0.9.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
            <version>1.5.3</version>
        </dependency>

2、测试controller中添加注解

@RestController
@Api(value="hello",description="测试get请求/hello")
public class HelloController {

    @RequestMapping("/hello")
    @ApiOperation(value="say hello",notes="hello",httpMethod ="GET",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String sayHello(){
        return "Hello!";
    }
}

3、访问路径:http://127.0.0.1:8081/swagger-ui.html

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值