1.当属性名相同 类型不同时,需要手动指明映射
@Mappings(
{
@Mapping(source = "customerType",target = "customerType"),
@Mapping(source = "customerStatus",target = "customerStatus")
)
List<CustomerBindDetailExcelVO> voListDtoToExport(List<CustomerBindDetailVO> records);
2.转换日期 date->string
@Mappings(
{
@Mapping(target = "relevanceTime",dateFormat = "yyyy-MM-dd HH:mm:ss"),
@Mapping(target = "authenticationTime",dateFormat = "yyyy-MM-dd HH:mm:ss")
}
)
List<CustomerBindDetailExcelVO> voListDtoToExport(List<CustomerBindDetailVO> records);
我在此设置了日期格式类型,但转换出来的格式合设置的不一致:为23-06-06 下午 05-16-12
解决方法:
1.自定义转换规则类
public class DateMapper {
public String asString(Date date) {
return date != null ? new SimpleDateFormat( "yyyy-MM-dd" )
.format( date ) : null;
}
public Date asDate(String date) {
try {
return date != null ? new SimpleDateFormat( "yyyy-MM-dd" )
.parse( date ) : null;
}
catch ( ParseException e ) {
throw new RuntimeException( e );
}
}
}
2.在MapStruct类上加上user属性指明转换规则类