修改API 输出格式
This commit is contained in:
@@ -101,7 +101,7 @@ namespace NX.ERP.WebAPi
|
||||
// those comments into the generated docs and UI. You can enable this by providing the path to one or
|
||||
// more Xml comment files.
|
||||
//
|
||||
c.IncludeXmlComments(string.Format("{0}/bin/NX.ERP.WebAPi.xml", System.AppDomain.CurrentDomain.BaseDirectory));
|
||||
// c.IncludeXmlComments(string.Format("{0}/bin/NX.ERP.WebAPi.xml", System.AppDomain.CurrentDomain.BaseDirectory));
|
||||
|
||||
// Swashbuckle makes a best attempt at generating Swagger compliant JSON schemas for the various types
|
||||
// exposed in your API. However, there may be occasions when more control of the output is needed.
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace NX.ERP.WebAPi
|
||||
|
||||
actionExecutedContext.Response.Content = new System.Net.Http.ObjectContent(typeof(ResultModel<string>),
|
||||
new ResultModel<string> { ErrCode = 500, ErrMsg = ex.Message, Data = null },
|
||||
new JsonMediaTypeFormatter());
|
||||
GlobalConfiguration.Configuration.Formatters.JsonFormatter);
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
@@ -47,11 +47,11 @@ namespace NX.ERP.WebAPi
|
||||
result.Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync<object>().Result;
|
||||
|
||||
//请求是否成功
|
||||
// result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode;
|
||||
//result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode;
|
||||
//结果转为自定义消息格式
|
||||
HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { Content = new ObjectContent<ResultModel<object>>(result, new JsonMediaTypeFormatter()) };
|
||||
actionExecutedContext.Response.Content = new ObjectContent<ResultModel<object>>( result, GlobalConfiguration.Configuration.Formatters.JsonFormatter);
|
||||
// 重新封装回传格式
|
||||
actionExecutedContext.Response = httpResponseMessage;
|
||||
// actionExecutedContext.Response = httpResponseMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,9 +80,16 @@ namespace NX.ERP.WebAPi
|
||||
{
|
||||
public static void Register(HttpConfiguration config)
|
||||
{
|
||||
|
||||
NX.ERP.U8.U8LoginContext.Instance.AccID = System.Configuration.ConfigurationManager.AppSettings["AccId"];
|
||||
NX.ERP.U8.U8LoginContext.Instance.PassWord = System.Configuration.ConfigurationManager.AppSettings["Password"];
|
||||
|
||||
NX.ERP.U8.U8LoginContext.Instance.UserId = System.Configuration.ConfigurationManager.AppSettings["UserId"];
|
||||
NX.ERP.U8.U8LoginContext.Instance.Server= System.Configuration.ConfigurationManager.AppSettings["Server"];
|
||||
|
||||
//System.Web.Http.Filters.IExceptionFilter
|
||||
config.Filters.Add(new ExceptionFilter());
|
||||
config.Filters.Add(new ApiResultAttribute());
|
||||
//config.Filters.Add(new ApiResultAttribute());
|
||||
Console.WriteLine(config.Filters.Count);
|
||||
// Web API 配置和服务
|
||||
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
|
||||
@@ -92,11 +99,11 @@ namespace NX.ERP.WebAPi
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
//Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
//小驼峰命名法
|
||||
//ContractResolver = new DefaultContractResolver()
|
||||
//{
|
||||
ContractResolver = new DefaultContractResolver()
|
||||
{
|
||||
|
||||
// NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
//}
|
||||
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
}
|
||||
//格式化日期时间
|
||||
|
||||
//空值处理
|
||||
|
||||
Reference in New Issue
Block a user