Swagger⼊参为List
今天遇到⼀个奇葩的需求,为了⽅便,service的⼀个接⼝⼊参是List<Map>
repayMoney(List<Map<String,Object>)
那,我为了在controller调⽤service,⼊参类型得⼀致呀,
那么问题来了,controller⼊参也得是List吧,或者是其他形式的数据,转换为List<Map>
翻遍了整个项⽬,没看到之前有⼈swagger的controller⾥⼊参是List的,⽽且查了⼀下,
⽤@ApiImplicitParams注解的话,⼊参只能是String或者Integer,啊,这可怎么办,类似于这样
关注点在⼊参为List,这个测试写的不完善,⼤家只要关注⼊参就可以了
@ApiOperation(value = "测试")
@RequestMapping(value = "/sanbiaoRepaymentAmount",method = RequestMethod.POST)
@ApiImplicitParams({@ApiImplicitParam(name = "idCard", dataType = "String", value = "⾝份证号", pa
ramType = "query", required = true),            @ApiImplicitParam(name = "userNo", dataType = "Integer", value = "编号", paramType = "query", required = true),
@ApiImplicitParam(name = "onePeriodAmount", dataType = "String", value = "⾦额", paramType = "query", required = true)})
@ResponseBody
public Result sanbiaoRepaymentAmount(@RequestParam(value = "idCard", required = true) String idCard,
@RequestParam(value = "userNo", required = true) Integer userNo,
@RequestParam(value = "onePeriodAmount", required = true) String onePeriodAmount) {
Result result = new ResultSupport();
List<Map<String,Object>> repayList = new ArrayList<Map<String,Object>>();
Map paramMap = new HashMap();
paramMap.put("idCard",idCard);
paramMap.put("userNo",userNo);
paramMap.put("onePeriodAmount",onePeriodAmount);
repayList.add(paramMap);
return result;
}
好吧,查了⼀下,好像去掉ApiImplicitParams,就可以传list,
于是我做了如下修改
@ApiOperation(value = "测试")
@RequestMapping(value = "/sanbiaoRepaymentAmount",method = RequestMethod.POST)
@ResponseBody
public Result sanbiaoRepaymentAmount(@RequestParam(value = "idCardList", required = true) List<String> idCardList,
@RequestParam(value = "userNoList", required = true) List<Integer> userNoList,
@RequestParam(value = "onePeriodAmountList", required = true) List<String> onePeriodAmountList) {
Result result = new ResultSupport();
List<Map<String,Object>> repayList = new ArrayList<Map<String,Object>>();
Map paramMap = new HashMap();
for(int i=0; i<idCardList.size(); i++){
//因为这⾥⼗分确定,三个⼊参list的长度是⼀致的,所以,在这⾥,把三个List对应的下标参数放在map⾥
paramMap.put("idCard",(i));
paramMap.put("userNo",(i));
param nameparamMap.put("onePeriodAmount",(i));
repayList.add(paramMap);
}
System.out.println("haha");
System.out.println(repayList);
    System.out.Class());
return result;
}
开始测试--Swagger⼊参是这样得,看吧,DataType 是Array,数组呗
逗号分隔参数,就可以咯
顺利经过测试,能⾛到repayMoney()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。