• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapstruct, service, controller - Send nested entity having (many-to-one relation) in the request

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

I have 2 entities Answer and Question with many-to-one relation as given below.



And I have QuestionRequestDTO with List<AnswerRequestDto>:



I have no idea how to connect these classes with mapstruct, servise, Restcontroller, Repository.
I try do it so:



I have no idea how to receive DTO in service and save in Repository, call in RestController...
 
Saloon Keeper
Posts: 15561
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not familiar with MapStruct, but as far as I can tell, you would just inject the mapper into your controller and then call it in one of your controller actions. Something like this:

I think you have to set the componentModel of your mappers to "spring" for this to work.

A word of warning. Automatic source code generation libraries are generally more trouble than they're worth. I can't speak for MapStruct, but Lombok is a huge pain.
 
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are  references to MapStruct:
https://www.baeldung.com/mapstruct

https://reflectoring.io/java-mapping-with-mapstruct/
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic