Skip to content
Advertisement

How to loop through a list payload and insert into database as individual row items in Springboot?

I am trying to insert items in a list in a database as single values in rows with the name of the sender. I am able to send the payload and insert into a single row with the user detailst. How can I loop through the payload sent and insert all the items into individual rows? I have tried to look for examples no luck. So far I can only insert as a single row in the database

this is the payload

JavaScript

My controller

JavaScript

My Service

JavaScript

My Model

JavaScript

Advertisement

Answer

Assuming that you were able to insert all labsigned in the payload into one single row with the code you mentioned in the question, You should iterate dispatched.labsigned and insert one by one as rows to accomplish what you need. And returning false at the end of method createDispatched will always return HttpStatus.BAD_REQUEST even though the records are successfully saved in the DB, so you might need to change it to return true.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement