我有ModelMapper
图书馆的问题。
实体类:
abstract class AbstractEntity {
Long id;
}
class User extends AbstractEntity {
String login;
Business business;
}
class Business extends AbstractEntity {
String name;
}
Dto类:
class NewUser {
String login;
Long businessId;
}
我如何模拟问题:
public class Main {
public static void main(String[] args) {
NewUser newUser = new NewUser();
newUser.setLogin("jhonatan.serafim");
newUser.setBusinessId(1L);
ModelMapper mapper = new ModelMapper();
User user = mapper.map(newUser, User.class);
System.out.println(user.getId());
System.out.println(user.getLogin());
System.out.println(user.getBusiness().getId());
}
}
预期的:
无效的
jhonatan.serafim
1
实际的:
1
jhonatan.serafim
1
解决这个问题的最佳方法是什么?