I'm mapping objects using below code snippet
@Mapper
@Configuration
public interface CommentMapper {
CommentMapper INSTANCE = Mappers.getMapper(CommentMapper.class);
@Mapping(source = "Id", target = "Id")
@Mapping(source = "remark", target = "remark")
Comment getComment(CommentDto postDto);
CommentDto getCommentDto(Comment post);
}
It doesnt map, but the moment I add this, it worked fine
@Mapper(imports = { Instant.class, DateTimeFormatter.class })
but not able to understand what it does? imports = { Instant.class, DateTimeFormatter.class }
how its helping to map objects?
As it is written in documentation , with "imports" you can set:
Additional types for which an import statement is to be added to the generated mapper implementation class.
In your case - it means that in generated CommentMapperImpl class, which will be generated as a realization of CommentMapper interface, two lines will be presented:
import path.to.class.DateTimeFormatter; // for example: java.time.format.DateTimeFormatter
import path.to.class.Instant;
If you use gradle you can find CommentMapperImpl.java here:
build/generated/sources/annotationProcessor/java/main/your/mapper/interface/package/CommentMapperImpl.java
for maven:
target/generated-sources/annotations/your/mapper/interface/package/CommentMapperImpl.java
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.