ConvertUtil.java 2.07 KB
Newer Older
刘基明's avatar
刘基明 committed
1 2 3
package com.tanpu.community.util;

import com.tanpu.community.api.beans.ThemeDTO;
刘基明's avatar
刘基明 committed
4
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
刘基明's avatar
刘基明 committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class ConvertUtil {

    public static ThemeDTO themeEntityToDTO(ThemeEntity themeEntity){
        ThemeDTO themeDTO = new ThemeDTO();
        BeanUtils.copyProperties(themeEntity, themeDTO);
        return themeDTO;
    }


    public static ThemeEntity themeDTOToEntity(ThemeDTO themeDTO){
        ThemeEntity themeEntity = new ThemeEntity();
        BeanUtils.copyProperties(themeDTO,themeEntity);
        return themeEntity;
    }

    public static List<ThemeDTO> themeEntitiesToDTOs(List<ThemeEntity> themeEntities){
        return themeEntities.stream().map(ConvertUtil::themeEntityToDTO).collect(Collectors.toList());
    }


    public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeDTO> themeDTOS){
        return themeDTOS.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
    }


    public static TopicDTO topicEntityToDTO(TopicEntity topicEntity){
        TopicDTO topicDTO = new TopicDTO();
        BeanUtils.copyProperties(topicEntity,topicDTO);
        return topicDTO;
    }

刘基明's avatar
刘基明 committed
44 45 46 47 48 49
    public static TopicBriefInfoDTO topicToBriefInfoDTO(TopicEntity topicEntity){
        TopicBriefInfoDTO topicBriefInfoDTO = new TopicBriefInfoDTO();
        BeanUtils.copyProperties(topicEntity,topicBriefInfoDTO);
        return topicBriefInfoDTO;
    }

刘基明's avatar
刘基明 committed
50 51 52
    public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities){
        return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
    }
刘基明's avatar
刘基明 committed
53 54 55 56

    public static List<TopicBriefInfoDTO> topicEntitiesToBriefDTOs(List<TopicEntity> topicEntities) {
        return topicEntities.stream().map(ConvertUtil::topicToBriefInfoDTO).collect(Collectors.toList());
    }
刘基明's avatar
刘基明 committed
57
}