Return the generated id

Asked

Viewed 162 times

-1

I am using Angular 6+ and springboot. As Gero an id and recover it?

ex: I have the following page: Imagem da pagina

When the user clicks on "New" will make a post. And this id that was generated will appear in the Code field.

*I thought I’d make a query and get the last id from the bank, but I’m afraid this processing time will take the id generated by another user.

  • 1

    Hello, you didn’t expose how your back-end structure is doing with spring boot. But, when persisting an element in the database is returned the element with the id created if it is auto increment or automatically generated. I recommend returning the persisted object on the back or even just id. Making another api call to fetch the last id is insecure and costly.

  • It is a simple post - Repository.save(Entity) where Entity contains all variables etc.

  • I commented on the case of returning the last id. Suppose I have 1000 users clicking the button at the same time. It will give conflict, no?

  • This control is performed in the backend. Check the Notation @Transaction and its parameters. One in particular is the Isolation >>Good coding!

1 answer

0


Put a (click) button on the button calling the post, and then you assign the searched id to the variable that is your ngModel in the HTML page

.then(Answer => { Sponse = Sponse.json(); this.id = Sponse.id; })

Places a loading while going to the server and every time you launch the new and enter the method to do the post always cleans the ID, not to risk using the previous.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.