MapperFacade的配置和使用(去掉不需要使用的属性 )

1,首先配置Pom文件

		
		    ma.glasnost.orika
		    orika-core
		

2,配置SpringBoot配置类,供全局使用

@Configuration
public class OrikaConfig {

	@Bean
	public MapperFactory mapperFactory() {
		return new DefaultMapperFactory.Builder().build();
	}
	
	@Bean
	public MapperFacade mapperFacade() {
		return mapperFactory().getMapperFacade();
	} 
}

3,使用@Autowired注入MapperFacade。

    @Autowired
    private MapperFacade mapperFacade;

4,准备两个Dto这里属性多的Dto我把称为 大 Dto,属性少的哪一方称为 少Dto

以下是大Dto  ----  对应的list我们把它叫做

List balancePayments
public class BalancePayment {

	private String id;

	private String userId;

	private String userPhone;
	
	private Double balance;


	private Integer sourceChannel;


	private Integer status;

	private Date editTime;


	private Date createTime;

	private String activeId;

	private String rejectRemarks;

	private String remarks;

	private String createSource;

}

以下是小Dto(小Dto就是我们开发当中需要用到属性) 对应的list我们把它叫做

List signBatchBalancePayments
public class BatchBalancePayment {


    private String userId;


    private String remarks;

    private Double balance;


}

5,开始转换

 List signBatchBalancePayments = mapperFacade.mapAsList(balancePayments, BatchBalancePayment.class);

 

经过以上步骤,就可以去掉无用的属性

 

 

 

 

 

 

 

你可能感兴趣的:(Java)