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