优化FromBody获取int类型字符串参数值

This commit is contained in:
不做码农 2023-07-13 12:32:55 +08:00
parent b8480c2bd8
commit c9b5aab7de

View File

@ -3,6 +3,7 @@ using Infrastructure;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System.Text.Json.Serialization;
using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Extensions;
using ZR.Admin.WebApi.Filters; using ZR.Admin.WebApi.Filters;
using ZR.Admin.WebApi.Framework; using ZR.Admin.WebApi.Framework;
@ -13,7 +14,6 @@ using ZR.Common.Cache;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
@ -80,6 +80,9 @@ builder.Services.AddMvc(options =>
}) })
.AddJsonOptions(options => .AddJsonOptions(options =>
{ {
options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString |
JsonNumberHandling.WriteAsString;
options.JsonSerializerOptions.WriteIndented = true;
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeConverter());
options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter()); options.JsonSerializerOptions.Converters.Add(new JsonConverterUtil.DateTimeNullConverter());
}); });