Dozer简单入门

maven引入依赖

 
            net.sf.dozer
            dozer
            5.2.1

创建映射文件xml



    
        handler.entity.Vo
        handler.entity.Po
        
            ss
            id
        
        
            username
            name
        
        
            time
            localTime
        
        
            path1
            image1
        
        
            path2
            image2
        
        
            path3
            image3
        
    

与spring整合




    
        
            
                classpath*:dozer/dozerBeanMapping.xml
            
        
    

test测试

import handler.entity.Po;
import handler.entity.Vo;
import org.dozer.Mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author whh
 * @date 2019/3/15 15:22
 */
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = {"classpath:spring-dozer.xml"})
public class Test2 {

    @Autowired
    Mapper mapper;
    @Test
    public void ss() {
        Po po = new Po();
        po.setId(110L);
        po.setName("测试");
        po.setImage1("11");
        po.setImage2("22");
        po.setImage3("33");
        Vo map = mapper.map(po, Vo.class);
        System.out.println("map = " + map);
    }
}

在这里插入图片描述

Dozer简单入门_第1张图片

你可能感兴趣的:(java)