• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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...
 
Bartender
Posts: 15737
368
  • 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: 2443
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/
 
Have you no shame? Have you no decency? Have you no tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic