Swagger2 忽略某些参数使其不出现在接口文档中

解决方案

    @ApiOperation("添加购物车")
    @ApiImplicitParams({
                @ApiImplicitParam(name = "token", required = true, value = "header token", paramType = "header", defaultValue = "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7InVzZXJJZCI6MjAsInVzZXJuYW1lIjoiMSIsInBhc3N3b3JkIjpudWx"),

            @ApiImplicitParam(name = "productId", value = "商品id", paramType = "query", dataType = "int", required = true)
    })
    @PostMapping
    public RespBean add(@ApiIgnore ShoppingCart shoppingCart) {
        ShoppingCart shop = new ShoppingCart();

        shop.setProductId(shoppingCart.getProductId());
        shop.setSkuId(shoppingCart.getSkuId());
        shop.setUserId(shoppingCart.getUserId());
        shop.setCartNum(shoppingCart.getCartNum());
        shop.setProductPrice(shoppingCart.getProductPrice());
        shop.setSkuProps(shoppingCart.getSkuProps());

        boolean save = shoppingCartService.save(shop);
        if (save) {
            return new RespBean(200, "添加收藏成功", null);
        } else {
            return new RespBean(555, "添加收藏失败", null);
        }
    }

在这里插入图片描述

    前后对比

之前在这里插入图片描述
添加@ApiIgnore之后

在这里插入图片描述

posted @ 2022-04-02 09:45  coderwcb  阅读(17)  评论(0编辑  收藏  举报