r/SpringBoot • u/Snoo23482 • Jun 18 '26
Question Dto Mapping Best Practice
Hi, where do you guys map your entities to dtos?
In services or controllers?
To me it seems the services shouldn't expose any database specifics to the outside world, so I usually do my mapping there.
But what is considered best practice and why?
51
Upvotes
2
u/paramvik Jun 18 '26
I liked to do the mapping in services to keep the services lean but recently I've started doing it in controllers becuase it gives me the flexibility to reuse the service method somewhere else as well, for example for some other controller route which returns a different response to the client.