zoukankan      html  css  js  c++  java
  • AutoMapper 9.0 简单用法

    AutoMapper.MapperConfiguration cfg = new AutoMapper.MapperConfiguration(q => { q.CreateMap(typeof(DTO), typeof(Model)); q.CreateMap(typeof(AddressDTO), typeof(AddressModel)); });
    DTO o = new DTO() { userName = "AAA" };
    o.address = new AddressDTO() { country = "China" };
    var m= cfg.CreateMapper().Map<Model>(o);
    Console.WriteLine(m.address?.country);

        public class DTO
        {
            public string userName { set; get; }
            public string age { set; get; }
            public string job { set; get; }
            public AddressDTO address { set; get; }
        }
    
    
        public class AddressDTO
        {
            public string country { set; get; }
            public string province { set; get; }
        }
        // Model
        public class Model
        {
            public string userName { set; get; }
            public string age { set; get; }
            public string job { set; get; }
            public AddressModel address { set; get; }
        }
        public class AddressModel
        {
            public string country { set; get; }
            public string province { set; get; }
        }
  • 相关阅读:
    配置log4j不同方法打印到不同的日志中
    Logging日志信息(转)
    Mybatis 动态sql
    mysql字段截取(转)
    tomcat多个端口配置
    Map,list,set,集合转化
    简单测试java
    java中有关自增的问题
    DMA复习
    笔试题
  • 原文地址:https://www.cnblogs.com/honk/p/12695087.html
Copyright © 2011-2022 走看看