java - Swagger Annotation向响应类添加json示例-LMLPHP

如何使用摇摇晃晃的注解插入默认值而不是“{}”?

最佳答案

您需要使用 @ApiResponses @ApiResponse 来标记Rest方法。

例如

@ApiResponses(value = {
                        @ApiResponse(code = 200, message = "Successful retrieval of demand",responseContainer="List"),
                        @ApiResponse(code = 404, message = "Demand does not exist", response = Your Error response.class),
                        @ApiResponse(code = 500, message = "Internal server error", response = Your Error response.class)
                    }
            )

使用 @ApiModel 取消您的Json Response类,并使用 @ApiModelProperty 取消其字段,例如
@ApiModel(description = "Your comment")
public class Demand implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(notes = "Your comments", required = true, example = "example value")
    private String demandId;
}

10-08 02:15