ModelMapper, mapping list of Entites to List of DTO objects

前端 未结 5 1208
深忆病人
深忆病人 2021-02-01 23:49

I am writing simple blog web application using Spring MVC framework. I am willing to add DTO layer to my app.

I decided to use ModelMapper framework for con

5条回答
  •  遇见更好的自我
    2021-02-02 00:06

    considering you have a list of Post Entity (postEntityList) and a PostDTO class, you can try following:

    use the following imports to get the desired results

    import org.modelmapper.ModelMapper;
    import org.modelmapper.TypeToken;
    import java.lang.reflect.Type;
    

    use the below code

    Type listType = new TypeToken>(){}.getType();
    List postDtoList = modelmapper.map(postEntityList,listType);
    

提交回复
热议问题