How to map a DTO to an existing JPA entity?

后端 未结 4 1429
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 10:49

I\'m trying to map a Java DTO object to an existing JPA entity object without having to do something like the following:

public MyEntity mapToMyEntity(SomeDT         


        
4条回答
  •  囚心锁ツ
    2021-01-02 11:26

    You can use dozer mapper or gson.

    DozerMapper ex:

    Mapper mapper = DozerBeanMapperBuilder.createDefault();
    DestinationObject destObject = mapper.map(sourceObject,DestinationClassName.class);
    

    You can check github page for more information

提交回复
热议问题