Swagger2
文章目录
快速入手
搭建
搭建springboot项目,略
-
导入swagger所需依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> -
controller代码
@RestController public class MyController { // 需指定使用的请求方法 @GetMapping("/hello") public String hello(String name){ return name; } } -
启动器添加@EnableSwagger2
-
localhost:port/swagger-ui.html
结果展示

方法接口参数调用
- 点击my-controller,点击Try it out

-
添加参数

-
返回的值

配置swagger
配置版本,文档信息
新建config类
@Configuration
public class SwaggerConfiguration {
/**
* Swagger的实例bean为docket,配置docket来配置Swagger具体参数
*
* @return
*/
@Bean
public Docket docket(){
// 配置版本swagger2.0 可通过源码查询配置参数
Docket docket = new Docket(DocumentationType.SWAGGER_2)

最低0.47元/天 解锁文章
1543





