解决转换后,postContentDto.postId没有赋值的问题。 需要增加一个postContentDto的转换方法,mapstruct并回去使用 PostContentMapper中的定义。

This commit is contained in:
many2many 2024-05-31 13:32:28 +08:00
parent baf2e8df7f
commit bacb030d3a

View File

@ -1,7 +1,9 @@
package com.lk.paopao.mapper; package com.lk.paopao.mapper;
import com.lk.paopao.dto.PostContentDto;
import com.lk.paopao.entity.Post; import com.lk.paopao.entity.Post;
import com.lk.paopao.dto.PostDto; import com.lk.paopao.dto.PostDto;
import com.lk.paopao.entity.PostContent;
import org.mapstruct.*; import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING) @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
@ -13,4 +15,7 @@ public interface PostMapper {
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
Post partialUpdate(PostDto postDto, @MappingTarget Post post); Post partialUpdate(PostDto postDto, @MappingTarget Post post);
@Mapping(source = "post.id", target = "postId")
PostContentDto toContentDto(PostContent postContent);
} }