5 changed files with 88 additions and 1 deletions
@ -0,0 +1,18 @@ |
|||||
|
package com.elink.esua.epdc.entity; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @author yujintao |
||||
|
* @email yujintao@elink-cn.com |
||||
|
* @date 2019/9/2 13:54 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TransforDemoEntity { |
||||
|
|
||||
|
private Long demoId; |
||||
|
|
||||
|
private String demoName; |
||||
|
|
||||
|
private int demoAge; |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.elink.esua.epdc.transfor; |
||||
|
|
||||
|
import com.elink.esua.epdc.entity.DemoEntity; |
||||
|
import com.elink.esua.epdc.entity.TransforDemoEntity; |
||||
|
import ma.glasnost.orika.MapperFactory; |
||||
|
import net.rakugakibox.spring.boot.orika.OrikaMapperFactoryConfigurer; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @author yujintao |
||||
|
* @email yujintao@elink-cn.com |
||||
|
* @date 2019/9/2 11:21 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class Demo2DemoTransforEntity implements OrikaMapperFactoryConfigurer { |
||||
|
|
||||
|
@Override |
||||
|
public void configure(MapperFactory orikaMapperFactory) { |
||||
|
orikaMapperFactory.classMap(DemoEntity.class, TransforDemoEntity.class) |
||||
|
.field("id", "demoId") |
||||
|
.field("name", "demoName") |
||||
|
.field("age", "demoAge") |
||||
|
.byDefault() |
||||
|
.register(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
package com.elink.esua.epdc; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.elink.esua.epdc.entity.DemoEntity; |
||||
|
import com.elink.esua.epdc.entity.TransforDemoEntity; |
||||
|
import ma.glasnost.orika.MapperFacade; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
/** |
||||
|
* 实体映射测试类 |
||||
|
* |
||||
|
* @author yujintao |
||||
|
* @email yujintao@elink-cn.com |
||||
|
* @date 2019/9/2 13:25 |
||||
|
*/ |
||||
|
@RunWith(SpringRunner.class) |
||||
|
@SpringBootTest |
||||
|
public class OrikaTest { |
||||
|
|
||||
|
@Autowired |
||||
|
private MapperFacade orikaMapper; |
||||
|
|
||||
|
@Test |
||||
|
public void Test() { |
||||
|
DemoEntity demoEntity = new DemoEntity(); |
||||
|
demoEntity.setId(1000L); |
||||
|
demoEntity.setName("name"); |
||||
|
demoEntity.setAge(19); |
||||
|
|
||||
|
TransforDemoEntity transforEntity = orikaMapper.map(demoEntity, TransforDemoEntity.class); |
||||
|
System.out.println(JSON.toJSONString(transforEntity)); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue