webapi 创建的基类成员是大写,返回给前端后变成小写的解决办法

安装 nuget:Microsoft.AspNetCore.Mvc.NewtonsoftJson
Model文件下创建的基类:

namespace WebApiTest1.Model
{
    public class Class
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int Type { get; set; }
        public DateTime CreateTime { get; set; }
    }
}

安装 Microsoft.AspNetCore.Mvc.NewtonsoftJson 之后再 Program.cs 文件配置 

builder.Services.AddControllers().AddNewtonsoftJson(options =>{
    //设置json返回格式
    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
    //设置所有的时间返回格式
    options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});

 

重新启动返回的就和配置的基类一样变为大写了

 

 

posted @ 2024-05-31 22:00  龙卷风吹毁停车场  阅读(132)  评论(0)    收藏  举报