mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1645 Use Repeatable Mapping annotation in the reference documentation
This commit is contained in:
parent
ced7f3b024
commit
2977c2e614
@ -21,13 +21,11 @@ This tells MapStruct to deviate from looking for a name `kind` at this level and
|
||||
@Mapper
|
||||
public interface FishTankMapper {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "fish.kind", source = "fish.type"),
|
||||
@Mapping(target = "fish.name", ignore = true),
|
||||
@Mapping(target = "ornament", source = "interior.ornament"),
|
||||
@Mapping(target = "material.materialType", source = "material"),
|
||||
@Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName")
|
||||
})
|
||||
@Mapping(target = "fish.kind", source = "fish.type")
|
||||
@Mapping(target = "fish.name", ignore = true)
|
||||
@Mapping(target = "ornament", source = "interior.ornament")
|
||||
@Mapping(target = "material.materialType", source = "material")
|
||||
@Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName")
|
||||
FishTankDto map( FishTank source );
|
||||
}
|
||||
----
|
||||
@ -57,15 +55,13 @@ Such is demonstrated in the next example:
|
||||
@Mapper
|
||||
public interface FishTankMapperWithDocument {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "fish.kind", source = "fish.type"),
|
||||
@Mapping(target = "fish.name", expression = "java(\"Jaws\")"),
|
||||
@Mapping(target = "plant", ignore = true ),
|
||||
@Mapping(target = "ornament", ignore = true ),
|
||||
@Mapping(target = "material", ignore = true),
|
||||
@Mapping(target = "quality.document", source = "quality.report"),
|
||||
@Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" )
|
||||
})
|
||||
@Mapping(target = "fish.kind", source = "fish.type")
|
||||
@Mapping(target = "fish.name", expression = "java(\"Jaws\")")
|
||||
@Mapping(target = "plant", ignore = true )
|
||||
@Mapping(target = "ornament", ignore = true )
|
||||
@Mapping(target = "material", ignore = true)
|
||||
@Mapping(target = "quality.document", source = "quality.report")
|
||||
@Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" )
|
||||
FishTankWithNestedDocumentDto map( FishTank source );
|
||||
|
||||
}
|
||||
|
@ -305,10 +305,8 @@ To create a mapper simply define a Java interface with the required mapping meth
|
||||
@Mapper
|
||||
public interface CarMapper {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "make", target = "manufacturer"),
|
||||
@Mapping(source = "numberOfSeats", target = "seatCount")
|
||||
})
|
||||
@Mapping(source = "make", target = "manufacturer")
|
||||
@Mapping(source = "numberOfSeats", target = "seatCount")
|
||||
CarDto carToCarDto(Car car);
|
||||
|
||||
@Mapping(source = "name", target = "fullName")
|
||||
@ -432,7 +430,8 @@ As an example let's assume the mapping from `Person` to `PersonDto` requires som
|
||||
@Mapper
|
||||
public interface CarMapper {
|
||||
|
||||
@Mappings({...})
|
||||
@Mapping(...)
|
||||
...
|
||||
CarDto carToCarDto(Car car);
|
||||
|
||||
default PersonDto personToPersonDto(Person person) {
|
||||
@ -456,7 +455,8 @@ The previous example where the mapping from `Person` to `PersonDto` requires som
|
||||
@Mapper
|
||||
public abstract class CarMapper {
|
||||
|
||||
@Mappings(...)
|
||||
@Mapping(...)
|
||||
...
|
||||
public abstract CarDto carToCarDto(Car car);
|
||||
|
||||
public PersonDto personToPersonDto(Person person) {
|
||||
@ -481,10 +481,8 @@ MapStruct also supports mapping methods with several source parameters. This is
|
||||
@Mapper
|
||||
public interface AddressMapper {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "person.description", target = "description"),
|
||||
@Mapping(source = "address.houseNo", target = "houseNumber")
|
||||
})
|
||||
@Mapping(source = "person.description", target = "description")
|
||||
@Mapping(source = "address.houseNo", target = "houseNumber")
|
||||
DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address);
|
||||
}
|
||||
----
|
||||
@ -514,10 +512,8 @@ MapStruct also offers the possibility to directly refer to a source parameter.
|
||||
@Mapper
|
||||
public interface AddressMapper {
|
||||
|
||||
@Mappings({
|
||||
@Mapping(source = "person.description", target = "description"),
|
||||
@Mapping(source = "hn", target = "houseNumber")
|
||||
})
|
||||
@Mapping(source = "person.description", target = "description")
|
||||
@Mapping(source = "hn", target = "houseNumber")
|
||||
DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn);
|
||||
}
|
||||
----
|
||||
@ -1954,15 +1950,13 @@ public interface SourceTargetMapper {
|
||||
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
|
||||
@Mappings( {
|
||||
@Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined"),
|
||||
@Mapping(target = "longProperty", source = "longProp", defaultValue = "-1"),
|
||||
@Mapping(target = "stringConstant", constant = "Constant Value"),
|
||||
@Mapping(target = "integerConstant", constant = "14"),
|
||||
@Mapping(target = "longWrapperConstant", constant = "3001"),
|
||||
@Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"),
|
||||
@Mapping(target = "stringListConstants", constant = "jack-jill-tom")
|
||||
} )
|
||||
@Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined")
|
||||
@Mapping(target = "longProperty", source = "longProp", defaultValue = "-1")
|
||||
@Mapping(target = "stringConstant", constant = "Constant Value")
|
||||
@Mapping(target = "integerConstant", constant = "14")
|
||||
@Mapping(target = "longWrapperConstant", constant = "3001")
|
||||
@Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014")
|
||||
@Mapping(target = "stringListConstants", constant = "jack-jill-tom")
|
||||
Target sourceToTarget(Source s);
|
||||
}
|
||||
----
|
||||
|
Loading…
x
Reference in New Issue
Block a user