mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-07 09:38:45 +08:00
AutoMapping 注解增加 reverseConvertGenerate,控制是否生成反向转换逻辑,适配更加复杂的应用场景
This commit is contained in:
parent
5f7860447f
commit
5c571181a2
@ -0,0 +1,15 @@
|
||||
package io.github.linpeilie.model;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
@AutoMapper(target = CarDto.class, imports = LocalDateTime.class)
|
||||
@Data
|
||||
public class Car1 {
|
||||
|
||||
@AutoMapping(target = "seatMaterial", source = "seatConfiguration.seatMaterial", reverseConvertGenerate = false)
|
||||
private SeatConfiguration seatConfiguration;
|
||||
|
||||
}
|
||||
@ -593,6 +593,7 @@ public class AutoMapperProcessor extends AbstractProcessor {
|
||||
// 默认的规则
|
||||
Map<String, AutoMappingMetadata> autoMappingMap =
|
||||
autoMapperMetadata.getFieldMappingList().stream()
|
||||
.filter(AutoMappingMetadata::getReverseConvertGenerate)
|
||||
.map(fieldMapping -> {
|
||||
final AutoMappingMetadata autoMappingMetadata = new AutoMappingMetadata();
|
||||
autoMappingMetadata.setSource(fieldMapping.getTarget());
|
||||
@ -919,6 +920,7 @@ public class AutoMapperProcessor extends AbstractProcessor {
|
||||
metadata.setTarget(elementName);
|
||||
}
|
||||
metadata.setTargetClass(targetClass);
|
||||
metadata.setReverseConvertGenerate(autoMappingGem.reverseConvertGenerate().get());
|
||||
metadata.setDefaultValue(autoMappingGem.defaultValue().getValue());
|
||||
metadata.setIgnore(autoMappingGem.ignore().getValue());
|
||||
metadata.setExpression(autoMappingGem.expression().getValue());
|
||||
|
||||
@ -9,6 +9,8 @@ public class AutoMappingMetadata {
|
||||
|
||||
private ClassName targetClass;
|
||||
|
||||
private boolean reverseConvertGenerate;
|
||||
|
||||
private String target;
|
||||
|
||||
private String source;
|
||||
@ -52,6 +54,14 @@ public class AutoMappingMetadata {
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
public boolean getReverseConvertGenerate() {
|
||||
return reverseConvertGenerate;
|
||||
}
|
||||
|
||||
public void setReverseConvertGenerate(boolean reverseConvertGenerate) {
|
||||
this.reverseConvertGenerate = reverseConvertGenerate;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@ -24,6 +24,13 @@ public @interface AutoMapping {
|
||||
|
||||
Class<?> targetClass() default DefaultMapping.class;
|
||||
|
||||
/**
|
||||
* 是否生成反向转换的逻辑
|
||||
*
|
||||
* @return true : 生成反向转换的逻辑 false : 不生成反向转换的逻辑
|
||||
*/
|
||||
boolean reverseConvertGenerate() default true;
|
||||
|
||||
/**
|
||||
* 来源,默认取当前字段名称
|
||||
* - 可以是当前类中的属性名
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user