展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

swagger2、knife4j使用

swagger2

http://服务器ip:端口/swagger-ui.html
  • 标注在接口类上
@Api("用于类")
  • 标注于方法,作为方法的简介
@ApiOperation(value = "apiOperationTest", notes = "apiOperation测试")
public void apiOperationSwaggerTest(){
}
  • 标注于方法:作为参数的简介
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer", paramType = "query"),@ApiImplicitParam(name = "name", value = "name", required = true, dataType = "String", paramType = "query")})
public void apiOperationSwaggerTest(Integer id, String name){
}
  • 标注于参数:设置默认值,设置是否必传
@ApiOperation(value = "apiOperationTest", notes = "apiOperation测试")
public void apiOperationTest(@ApiParam(name = "id", value = "1", required = true) Integer id){
}
  • 标注于实体类
@ApiModel(description = "实体类", value = "实体类")
public class City implements Serializable {
}
  • 标注于实体类的参数
@ApiModelProperty(name = "id", value = "编号", required = false, exmaple = "1")
private int id;
@ApiModelProperty(name = "name", value = "城市名字", dataType = "String", example = "Kabul")
private String Name;

knife4j

http://localhost:8080/doc.html
  • 标注于接口类
@Api(tags = "学生相关接口")
  • 标注于接口方法
@ApiOperation("增加学生(json方式提交)")
  • 标注接口方法,指明响应参数
@ApiResponses({@ApiResponse(code = 200, message = "ok", response = DietitianDetailDTO.class)})
  • 标注于参数
@ApiImplicitParam(name = "name", value = "学生姓名", dataTypeClass = String.class, required = true)
public R<Student> get(String name) {
    return R.ok(new Student(new Random().nextLong(), "杜甫", 21, 175));
}

@ApiOperation("分页查询")
@ApiImplicitParams({@ApiImplicitParam(name="tFoodVO",value="查询条件",dataType = "TFoodVO",required = true),})
public JSONResult pageFood(TFoodInfoVO tFoodVO){
    return tFoodService.findPage(tFoodVO);
}
  • 标注于实体类
@ApiModel(value = "学生表单")
@ApiModel(value="TFoodInfo对象", description="食材表")
  • 标注于实体类参数
@ApiModelProperty(value = "姓名", example = "李白")
private String name;
posted @ 2022-04-02 22:04  DogLeftover  阅读(47)  评论(0编辑  收藏  举报