zoukankan      html  css  js  c++  java
  • 关于swagger——WebApi一个controller中出现多个Get是出现错误的处理

     /// <summary>
        /// 测试处理
        /// </summary>
        public class TestController : ApiController
        {
            /// <summary>
            /// 根据角色获取该角色所有拥有的功能
            /// </summary>
            /// <param name="roleid"></param>
            /// <returns></returns>
            [HttpPost]
            [Common.AccessToken]
            public Common.ResponseHeader GetByRole(int roleid)
            {
                return new Common.ResponseHeader { code=0,msg="",data=null};
            }
    
            /// <summary>
            /// 获取所有功能
            /// </summary>
            /// <returns></returns>
            [HttpGet]
            [Common.AccessToken]
            public Common.ResponseHeader GetAll()
            {
                return new Common.ResponseHeader { code = 0, msg = "", data = null };
            }
            /// <summary>
            /// 获取所在代理下的所有功能
            /// </summary>
            /// <param name="id">ces</param>
            /// <returns></returns>
            [HttpGet]
            [Common.AccessToken]
            public Common.ResponseHeader GetAll(int id)
            {
                return new Common.ResponseHeader { code = 0, msg = "", data = null };
            }
        }
    

     这段代码会产生如下图的结果:

    解决方案

    对WebApiConfig中的路由进行修改

    config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{action}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );

    重新运行  问题得到解决

  • 相关阅读:
    织梦系统的安装与详细信息
    js 报错 :object is not a function
    css3中动画animation的应用
    js 中 setTimeout()的用法
    CSS3 Gradient-CSS3渐变
    css3 transform 变形
    CSS3 transition 属性
    只要有人的地方,世界就不是冰冷的。
    CSS层
    css区块定位之浮动与清除属性
  • 原文地址:https://www.cnblogs.com/wang0020/p/9036198.html
Copyright © 2011-2022 走看看