Java教程

b-abp05(automapper)

本文主要是介绍b-abp05(automapper),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

新增dto

 public class UserDto  : EntityDto<int>
    {
        public string UserNo { get; set; }
        public string UserName { get; set; }
        public int RoleId { get; set; }
        public string Password { get; set; }
    }

新增profile

 public class UserProfile : Profile
    {
        public UserProfile()
        {
            CreateMap<User, UserDto>();
        }
    }

在applicationmodule中使用,并添加profile中

[DependsOn(
        typeof(AbpDddApplicationModule),
        typeof(AbpAutoMapperModule),
        typeof(MVCEntityFrameWorkModule)
        )]
    public class MVCApplicationModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpAutoMapperOptions>(opt =>
            {
                opt.AddProfile<UserProfile>();
            });
        }
    }

在service中使用

public async Task<UserDto> getAsync(string UserNo, string password)
        {
            var user = await _users.GetAsync(m => m.UserNo == UserNo && m.Password == password);
            return ObjectMapper.Map<User, UserDto>(user);
        }

到此为止。

这篇关于b-abp05(automapper)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!