springboot 集成swagger ui

springboot 配置swagger ui

1. 添加依赖

<!-- swagger ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>

2. 启动swagger ui注解

@SpringBootApplication
@EnableSwagger2
public class Main {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Main.class, args);
    }
}

3.添加 controller注解

@RestController
@RequestMapping("/user")
@Api("swagger ui 注释 api 级别")
public class HelloWorldController {

    @ApiOperation("swagger ui 注释 方法级别")
    @RequestMapping(value="/hello",method=RequestMethod.GET)
    public  String hello() {
        String data = "Never trouble untill trouble troubles you. Some one told me some years ago.";
        return data;
    }
}

4. swagger ui 链接: localhost:8080//swagger-ui.html (默认)

 

参考这里

 

posted @ 2018-01-07 10:27  pkyou  阅读(5965)  评论(0编辑  收藏  举报