I'm working on REST in Spring Boot and I'm wondering how to deal with DTO
, what is proper approach. I read many Q/A here at SO and articles on the web and not sure if I get it correctly.
I use DTO
s because REST API do not handle all information from domain model classes. I have such REST api endpoint:
@PostMapping("/")
public ResponseEntity<APIResponse> add(@RequestBody EnvelopeDTO envelope) {
// calling service layer and saving envelope data and returning new envelope....
}
My question - In my case (when I use DTO
in my app as I mentioned above): should service layer accept EnvelopeDTO or should I in controller remap DTO
into Envelope
domain object and use it instead of EnvelopeDTO
?
Or more simply, should service layer in general work (accept as input parameters and produces as output) with DTOs
or with domain models? Is there some best practice or recommender pattern for this?
Aucun commentaire:
Enregistrer un commentaire