swagger3 传参格式

PageQuery.java

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class PageQuery {

    @Schema(description = "当前页数", example = "1", required = true)
    private Integer pageNum;

    @Schema(description = "每页记录数", example = "5", required = true)
    private Integer pageSize;
}

TestController.java

import java.util.Date;
import java.util.List;

import com.example.eduserver.param.TestAddParam;
import com.example.eduserver.param.TestEditParam;
import com.example.eduserver.query.PageQuery;
import com.example.eduserver.result.PageResult;
import com.example.eduserver.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.eduserver.entity.Test;
import com.example.eduserver.service.ITestService;

@RestController
@Tag(name = "测试")
@RequestMapping("/test")
public class TestController {
	@Autowired
	private ITestService testService;

	@Operation(summary = "分页查询")
	@PostMapping("/page")
	public Result pageTestInfo(@RequestBody PageQuery pageQuery) {
		PageResult page = testService.getPage(pageQuery);
		return new Result(page);
	}
}

@RequestBody 为json格式 swagger页面长这样

将注解换成 @ModelAttribute @ParameterObject 即可看到表单式的swagger

public Result pageTestInfo(@ParameterObject PageQuery pageQuery) {
	PageResult page = testService.getPage(pageQuery);
	return new Result(page);
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Swagger-YAML是一种用于描述RESTful API的标记语言。它使用YAML格式来编写API的各种信息,包括API的基本信息、路径、操作和其他元数据。 以下是一个Swagger-YAML格式的示例: ```yaml swagger: '2.0' info: version: 1.0.0 title: Pet Store API description: This API provides endpoints for managing a pet store paths: /pets: get: summary: Get all pets produces: - application/json responses: 200: description: Successful operation schema: type: array items: $ref: '#/definitions/Pet' post: summary: Add a new pet consumes: - application/json parameters: - in: body name: pet description: Pet object that needs to be added to the store schema: $ref: '#/definitions/Pet' responses: 201: description: Pet created /pets/{id}: get: summary: Get pet by ID produces: - application/json parameters: - name: id in: path required: true type: integer format: int64 responses: 200: description: Successful operation schema: $ref: '#/definitions/Pet' put: summary: Update pet by ID consumes: - application/json parameters: - name: id in: path required: true type: integer format: int64 - in: body name: pet description: New details of the pet schema: $ref: '#/definitions/Pet' responses: 200: description: Pet updated 404: description: Pet not found definitions: Pet: type: object properties: id: type: integer format: int64 name: type: string ``` 上述示例中,我们定义了一个名为Pet Store API的RESTful API,并定义了两个路径:/pets和/pets/{id}。每个路径下有对应的操作,如获取所有宠物、添加新宠物、通过ID获取特定宠物和更新特定宠物等。 Swagger-YAML格式使用了一些关键字来描述各种信息,比如info用于提供API的基本信息,paths用于定义各个路径下的操作,definitions用于定义数据模型等。 通过使用Swagger-YAML格式,我们可以清晰地描述API的结构和功能,并可以自动生成API文档、客户端代码和服务器模拟等。这样可以提高团队的协作效率,并方便了解和使用API。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值