码迷,mamicode.com
首页 > 编程语言 > 详细

Springboot继承swagger2

时间:2019-01-25 00:20:14      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:return   str   operation   ima   enc   htm   web   group   添加   

1、添加pom依赖:

        <!-- 添加swagger相关依赖 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>

2、启动类上添加@EnableSwagger2注解:

@EnableSwagger2

3、在Controller类上添加@Api注解,方法上添加@ApiOperation注解:

package cn.mmweikt.es.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("test")
@Api("测试")
public class TestController {

    @GetMapping("test1")
    @ResponseBody
    @ApiOperation("测试")
    public String test(){
        return "test1";
    }
}

4、访问http://127.0.0.1:8080/swagger-ui.html验证:
技术分享图片

Springboot继承swagger2

标签:return   str   operation   ima   enc   htm   web   group   添加   

原文地址:https://www.cnblogs.com/kibana/p/10317555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!