1. 程式人生 > >springmvc 介面使用標籤,配合swagger方便輸出介面資訊

springmvc 介面使用標籤,配合swagger方便輸出介面資訊

@RestController
@Api(description = "商品介面")
public class ProductController {

    @GetMapping(value = "productList")
    @ApiOperation(value = "商品列表介面",notes = "沒有什麼特別的說明")
    //paramType 有五個可選值 : path, query, body, header, form
    @ApiImplicitParams({@ApiImplicitParam(value = "當前第幾頁",name = "page",paramType 
= "query",required = true), @ApiImplicitParam(value = "每頁多少條資料",name = "pageSize",paramType = "query")}) public List<ProductPo> productList(Integer page,Integer pageSize){ List<ProductPo> list = new ArrayList<>(); ProductPo product = new ProductPo(); product.setId(1L
); product.setName("無線網絡卡"); product.setPrice(111122223333L); list.add(product); product = new ProductPo(); product.setId(2L); product.setName("無線網絡卡 200m"); product.setPrice(6666666666L); list.add(product); return list; } @ApiOperation
(value = "查詢商品",notes = "沒有啥特別說明") @PostMapping(value = "queryProduct") public List<ProductPo> queryProduct(@ApiParam(value = "商品查詢物件") @RequestBody ProductPo productPo){ List<ProductPo> list = new ArrayList<>(); ProductPo product = new ProductPo(); product.setId(1L); product.setName("無線網絡卡"); product.setPrice(111122223333L); list.add(product); return list; }

 

@Data
@ApiModel(value = "商品實體",description = "商品物件,這個也沒什麼好介紹的")
public class ProductPo implements Serializable {
    private static final long serialVersionUID = 1933607002870882876L;

    @ApiModelProperty(hidden = true)
    private Long id;

    @ApiModelProperty(value = "商品名稱",name = "productName",required = true)
    private String name;

    @ApiModelProperty(value = "商品價格",notes = "單位為分")
    private Long price;

}


更多關於swagger的標籤請網上搜索