swagger,参数,list,swaggerui测试list类型参数示例

在ASP.net、C#、.netfreamwork环境下:

使用swaggerui时,如果入参格式为 List,List 等形式,后台经常无法接收到参数,接收到的值为null,或count为0:

 

一、HttpGet示例:

后台示例:

1.经测试,后台List,List格式的入参,HttpGet必须加参数属性  [FromUri] 

 http://192.168.0.101:9085/api/History/GetDaySignalSummary?summaryList=1&summaryList=2&startTime=2020-03-30&stationId=11010801-6561-41cb-b131-e812f09daab6

 

        /// 
        /// 获取历史数据合计
        /// 
        /// 
        /// 
        ///      
        /// 
        /// 
        [ActionsGroup("统计数据获取")]
        [HttpGet]
        public JObject GetSignalSummary([FromUri]List<int> summaryList, string startTime, string endTime, string stationId)
        {
            JObject result = new JObject();
            try
            {
                RedisHelper redisStruct = new RedisHelper((int)EnumUserRedisNum.Struct);
                cfg_station station= redisStruct.HashGet(ConstValue.Area, stationId);
                history_signalsummaryBLL summaryBLL = new history_signalsummaryBLL();
                JObject temp = summaryBLL.GetSignalSummary(station.keycode, summaryList, startTime, endTime);
                if (temp == null)
                {
                    result.Add("Code", (int)EnumExecStatus.失败);
                    result.Add("Error", "未获取到历史数据");
                    return result;
                }
                result.Add("Code", (int)EnumExecStatus.成功);
                result.Add("Result", temp);
            }
            catch (Exception ex)
            {
                LogEvent.LogInfo.Fatal(ex.ToString());
                result.Add("Code", (int)EnumExecStatus.失败);
                result.Add("Error", ex.ToString());
            }
            return result;
        }

 

swagger,参数,list,swaggerui测试list<string>类型参数示例_第1张图片

 

 

 SwaggerUI调用示例:

swagger,参数,list,swaggerui测试list<string>类型参数示例_第2张图片

 

 

 

 

二、HttpPost示例:

1.经测试,后台List,List格式的入参,

2.参数格式填写错误:需要填写成如下格式:

["1","2","3"]

swagger,参数,list,swaggerui测试list<string>类型参数示例_第3张图片

 

你可能感兴趣的:(技术)