小编bhu*_*ana的帖子

使用mapstruct从List <Object>映射List <String>

嗨我在使用mapstruct从Child Source类设置它时,在DTO中为List操作获取null.有人可以帮我解决这个问题.请在这里找到我的代码

实体类:

public class Source {
    int id;
    String name;
    List<ChildSource> childSource;
    //getters and setters
}

public class ChildSource {
    String code;
    String action;
    //getters and setters   
}
Run Code Online (Sandbox Code Playgroud)

DestinationDTO:

public class TargetDTO{
    int sNo;
    String mName;
    List<String> actions;
    //getters and setters  
}
Run Code Online (Sandbox Code Playgroud)

MApper类:

@Mapper(componentModel = "spring")    
public abstract class SampleMapper {
        @Mappings({ 
            @Mapping(target = "id", source = "sno"),
            @Mapping(target = "name", source = "mNAme")
        })
        public abstract TargetDTO toDto(Source source);

        @IterableMapping(elementTargetType = String.class)
        protected abstract List<String> mapStringtoList(List<ChildSource> childSource);

        protected …
Run Code Online (Sandbox Code Playgroud)

java dto mapstruct

7
推荐指数
1
解决办法
3510
查看次数

标签 统计

dto ×1

java ×1

mapstruct ×1