I
I
IvanN7772021-04-30 16:36:03
Java
IvanN777, 2021-04-30 16:36:03

How to organize a complex DTO from multiple entities?

Let's say there is an entity user
the user has roles the role has permissions
the user has a subject

I do something for the data from the form, with the usual one I just encapsulate the input and form the entity.
And how do they do this when there are nestings, you can link to the article.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-04-30
@IvanN777

Well, you can create several DTOs by analogy with the necessary entities from the database.
For example,

class User {
Role role;
}
class Role {
List<Privilege> privileges;
}

class UserDto {
RoleDto role;
}
class RoleDto {
List<PrivilegeDto> privileges;
}

If the names match, then the mappers will be able to convert Dto <--> Entity, otherwise, you will need to customize the mappers or add the appropriate annotations. You can take the same MapStruct || ModelMapper or use springConverter<>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question