<!--swagger3-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
src/main/java/com/example/demo/config/SwaggerConfig.java
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springOpenAPI() {
return new OpenAPI().info(new Info()
.title("SpringDoc API Test")
.description("SpringDoc Simple Application Test")
.version("1.0.0"));
}
}
对控制器使用 @Tag
@Tag(name = "User", description = "User 接口")
对接口使用 @Operation
@Operation(description = "分页查询用户信息")
完整示例
@Tag(name = "User", description = "User 接口")
@RestController
@RequestMapping("/demo/user")
public class UserController {
@Autowired
private IUserService userService;
@GetMapping("/{page}/{pageSize}")
@Operation(description = "分页查询用户信息")
public IPage<User> pageQuery(@PathVariable Integer page, @PathVariable Integer pageSize) {
return userService.pageQuery(page, pageSize);
}
}
效果