NetCore 使用 AutoMapper
引用Nuget包
AutoMapper AutoMapper.Extensions.Microsoft.DependencyInjection
配置Program.cs
//添加Profile builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
配置Profile
public class AutoMapperProfile : Profile
{
/// <summary>
/// 实体映射
/// </summary>
public AutoMapperProfile()
{
#region 接口映射
//DTO映射到源数据
CreateMap<InterDto, InterModel>();
#endregion
}
}
控制器使用
var model = _mapper.Map<InterModel>(modelDto);
参考:https://www.cnblogs.com/myfqm/p/12982203.html

浙公网安备 33010602011771号