swagger界面非必传参数的设置


修改之前:

第一次代码实现:
@RequestMapping(path="/getByStoreAndTypeAndSn/{storeId}/{versionType}/{terminalSn}", method=RequestMethod.GET )
public TerminalSet getListByStoreIdAndVersionAndSn(@PathVariable("storeId") Long storeId,@PathVariable("versionType") Integer versionType,@PathVariable("terminalSn") String terminalSn){
    return terminalSetService.getListByStoreIdAndVersionAndSn(storeId,versionType,terminalSn);
}

第二次代码实现:
@ApiOperation(value="根据分店编号和版本类型,设备Sn号获取注册信息,用于设备加载时认证")
@RequestMapping(path="/getByStoreAndTypeAndSn", method=RequestMethod.GET )
@ApiImplicitParams({
@ApiImplicitParam(name="storeId",value="部门编号",paramType = "query"),
@ApiImplicitParam(name="versionType",value="版本类型(0-总店版 1-门店版 2-收银台版)",allowableValues="0,1,2",paramType = "query",required=true),
@ApiImplicitParam(name="terminalSn",value="设备Sn号",paramType = "query",required=true),
})
public TerminalSet getListByStoreIdAndVersionAndSn(@RequestParam Long storeId, @RequestParam Integer versionType,@RequestParam String terminalSn){
return terminalSetService.getListByStoreIdAndVersionAndSn(storeId,versionType,terminalSn);
}



修改之后:
@ApiOperation(value="根据分店编号和版本类型,设备Sn号获取注册信息,用于设备加载时认证")
@RequestMapping(path="/getByStoreAndTypeAndSn", method=RequestMethod.GET )
@ApiImplicitParams({
@ApiImplicitParam(name="storeId",value="部门编号",paramType = "query",required=false),
 @ApiImplicitParam(name="versionType",value="版本类型(0-总店版 1-门店版 2-收银台版)",allowableValues="0,1,2",paramType = "query",required=true),
@ApiImplicitParam(name="terminalSn",value="设备Sn号",paramType = "query",required=true),
})
public TerminalSet getListByStoreIdAndVersionAndSn( Long storeId, Integer versionType, String terminalSn){
return terminalSetService.getListByStoreIdAndVersionAndSn(storeId,versionType,terminalSn);
}

总结:
设置非必传参数时,不能用
/getByStoreAndTypeAndSn/{storeId}/{versionType}/{terminalSn} 这种方式传参
当使用 @ApiImplicitParams注解时已经设置了参数的的基础信息,就无须再使用 @RequestParam注解
如果未使用@ApiImplicitParams注解时,用 @RequestParam注解来设置需要传入的参数,此时需要用 required 来设置是否为必传参数,true为必传,false为非必传。



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM