常见的问题系列---【@ApiOperationSupport忽略失效的问题】

1.问题

knife4j提供了一个@ApiOperationSupport(ignoreParameters = {"sysDict.id,sysDict.status"})注解,可以在新增时忽略掉一些无关的字段。可是我在用的时候,犯了一个低级错误,排查了半天。

2.问题复现

错误代码:

@ApiOperation(value = "添加")
    @ApiOperationSupport(ignoreParameters = {"sysDict.id,sysDict.status"})
    @PostMapping("/add")
    public R<Boolean> insert(@RequestBody SysDict sysDict) {
        return success(this.sysDictService.save(sysDict));
    }

正确代码:注意紫色部分,一定是一个字段一对引号。

@ApiOperation(value = "添加")
    @ApiOperationSupport(ignoreParameters = {"sysDict.id","sysDict.status"})
    @PostMapping("/add")
    public R<Boolean> insert(@RequestBody SysDict sysDict) {
        return success(this.sysDictService.save(sysDict));
    }

扩展:

1. 一级参数

@ApiOperation(value = "新增Model接口1")
@ApiOperationSupport(ignoreParameters = {"id","orderDate.id"})
@PostMapping("/insertMode1l")
public Rest<UptModel> insertModel1(UptModel uptModel){
    Rest<UptModel> r =new Rest<>();
    r.setData(uptModel);
    return r;
}

UptModel.java

public class UptModel {

    @ApiModelProperty(value = "主键id")
    private String id;

    @ApiModelProperty(value = "姓名")
    private String name;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "订单信息")
    private OrderDate orderDate;
}

2. JSON参数

@ApiOperation(value = "新增Model接口")
@ApiOperationSupport(ignoreParameters = {"uptModel.id","uptModel.name","uptModel.orderDate.id"})
@PostMapping("/insertModel")
public Rest<UptModel> insertModel(@RequestBody UptModel uptModel){
    Rest<UptModel> r =new Rest<>();
    r.setData(uptModel);
    return r;
}

3.json对象套数组

   @PostMapping("/saveHead")
    @ApiOperationSupport(order = 3, ignoreParameters = {"param.id", "param.taxOrgName", "param.applyUserName", "param.deptName", "param.projectName", "param.invTypeName", "param.payStatusName", "param.invStatus", "param.invStatusName", "param.reconcile", "param.reconcileName", "param.bookkeeping", "param.bookkeepingName",
        "param.invCompanyCode", "param.invCompanyName", "param.invCompanyAddress", "param.invCompanyTaxSubjectNum", "param.custName", "param.custTaxNum", "param.custAddress", "param.businessFieldVoList[0].id", "param.businessFieldVoList[0].goodsName",
        "param.businessFieldVoList[0].status", "param.businessFieldVoList[0].statusName", "param.businessFieldVoList[0].reconcileName"
    })
    @ApiOperation(value = "新增表头表体", notes = "新增表头表体")
    public R saveHead(@Valid @RequestBody BusinessVo param) {
        //1:OA新增  2:系统新增
        param.setSource(2);
        return businessService.saveHead(param);
    }

 

上一篇:pache配置文件分析


下一篇:java学习路线第一课