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 (默認)

 

參考這里

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM