Swagger3 使用示例
Swagger3 使用示例
GET 请求,传递 query-string 参数
@Operation(summary = "GET 请求", description = "GET 请求传递 query-string 参数", tags = {"用户管理"})
@GetMapping(value = "/get-query-string", produces = "application/json")
ResponseResult<Void> getDemo(
@Parameter(in = ParameterIn.QUERY, description = "用户名", required = true) @RequestParam(value = "username") String username,
@Parameter(in = ParameterIn.QUERY, description = "密码", required = true) @RequestParam(value = "password") String password) {
...
}
POST 请求,传递 query-string 参数
@Schema(description = "用户登录信息")
public class User {
@Schema(name = "username", example = "tommy", required = true, description = "用户名")
private String username;
...
}
@Operation(summary = "POST 请求 1", description = "POST 请求传递 query-string 参数", tags = {"用户管理"})
@PostMapping(value = "/post-query-string", consumes = {"application/x-www-form-urlencoded"}, produces = {"application/json"} )
ResponseEntity<String> postDemo1(@Parameter(in = ParameterIn.DEFAULT, description = "", schema = @Schema(implementation = User.class)) User user) {
...
}
POST 请求,传递 json-string 参数
@Operation(summary = "POST 请求 3", description = "POST 请求传递 json-string 参数", tags = {"用户管理"})
@PostMapping(value = "/post-json-string", consumes = "application/json", produces = "application/json" )
public ResponseEntity<String> worldUsingPostUsingPOST(@Parameter(in = ParameterIn.DEFAULT, description = "用户信息表单对象", schema = @Schema(implementation = User.class)) @RequestBody User user) {
...
}
原文地址:https://blog.csdn.net/m0_73393501/article/details/137891995
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!