How to customize ModelMapper

后端 未结 4 1593
独厮守ぢ
独厮守ぢ 2020-12-13 01:16

I want to use ModelMapper to convert entity to DTO and back. Mostly it works, but how do I customize it. It has has so many options that it\'s hard to figure out where to st

4条回答
  •  醉酒成梦
    2020-12-13 01:50

    import org.modelmapper.ModelMapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    @Service
    public class EntityDtoConversionUtil {
    
        @Autowired
        private ModelMapper modelMapper;
    
        public Object convert(Object object,Class type) {
    
            Object MapperObject=modelMapper.map(object, type);
    
            return MapperObject;
    
        }
    
    
    }
    

提交回复
热议问题