Skip to content
Advertisement

Get values from User and update into mysql database in Springboot Controller

I’m developing a Banking system Project Where User Should be able to create an account in any available branch. Branch Creation will be maintained by admin. I had two tables(Entities) like BranchDetails and AccountDetails. db_Structure The BranchId Column is the primary key in BranchDetails and Foreign key in AccountDetails. Now When user Creates an account, he will input the Preferred Branch name and the AccountHolder name. I had to Insert this Account in AccountDetails Table which matching the branchId which the user had entered.

How do i achive this. So far i have tried,

BranchDetails.java

JavaScript

AccountDetails.java

JavaScript

Controller

JavaScript

Advertisement

Answer

Prepare AcCreation method to receive branch id (the branches already exist, so you could send their ids and names to your frontend form’s select component) and customer name (provided by the user in the input field):

It would look like this (I changed the name to createAccount, because it sounds naturally, there is no need to use shortcuts in method’s name, but in the end it’s your choice):

JavaScript

Look at the removed code from the service method.

Details connected with creation on the database should be contained by database access layer, in this case the class AccountRepository and database layer methods should be called by service’s methods – in your case we left out the service class).

So you would create Account instance inside its method and then set the branchId field.

Or you could do something like this (you would have to have two separate repositories, one for AccountDetails, second for BranchDetails entities):

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