1、在pom.xml文件配置maven依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2、配置Swagger
2.1 (必选)添加开关注解@EnableOpenApi
3、在controller类写一个测试的方法
@RestController
@Api(tags = "测试用例")
public class TestController {
@GetMapping("fun")
@ApiOperation("fun测试方法")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "String", name = "name", value = "用户名", required = true, example = "lucky"),
@ApiImplicitParam(paramType = "query", dataType = "Integer", name = "age", value = "年龄", required = false, example = "19"),
})
public String fun(String name,Integer age){
System.out.println(name);
System.out.println(age);
return "hello!lucky";
}
}
4、访问官网的url地址的路径:/swagger-ui/index.html
效果图: