Leave a Reply

33 Comments on "Spring Boot Quick Start 20 – Implementing Update and Delete"

Notify of
avatar

shashgo
Guest
shashgo
6 days 2 hours ago
I have a question about Rest websites, about how to deploy a rest website, so that a user can use it like an ordinary website. If I create a website with html, then all I do is to upload it to a host like hostgator or godaddy, so that it is available to rest of the internet, and that anyone anyone can log on to their browser and access it. But how do I do that with a rest website? Do web host normally support java and spring boot? Also , how would a user send different kinds of requests:… Read more »
Victim of the System
Guest
Victim of the System
22 days 6 hours ago

Simpler version for updateTopic method public void updateTopic(String id, Topic topic) { for (Topic element : topics) { if (element.getId().equals(id)) { topics.set(topics.indexOf(element), topic); } }

Lê Thanh Liêm
Guest
Lê Thanh Liêm
1 month 5 days ago

The issue could be happened if the id and the id in the body is different. Instead of update it will replace.In my opinion,It could be implement without id in the update method: public void updateTopic(Topic topic) { for(int i = 0; i <= topics.size(); i++) { if(topics.get(i).getId().equals(topic.getId())) { topics.set(i, topic); return; } } } @RequestMapping(method=RequestMethod.PUT, value="/topics") public void updateTopic(@RequestBody Topic topic) { topicService.updateTopic(topic); }

Wayne Covell
Guest
Wayne Covell
3 months 13 hours ago

For those asking for a simpler expression for the updateTopic, you can use: public void updateTopic(String id, Topic topic) { topics = topics.stream().map(t -> { return t.getId().equals(id) == true ? topic : t; }).collect(Collectors.toList()); }

drsgi8
Guest
drsgi8
8 days 8 hours ago

Loop will be slightly quicker but map().collect() is far more readable and scalable. Also body around lambda expressions and "== true" are unnecessary

Prasad Amberkar
Guest
Prasad Amberkar
2 months 5 days ago

Which one is more efficient performance wise? for loop or lambda expression?

Sireesh V
Guest
Sireesh V
3 months 5 days ago

We can make use of @GetMapping, @PostMapping, @PutMapping and @DeleteMapping in place of @RequestMapping(method=RequestMethod….)

subash8181
Guest
subash8181
11 days 10 hours ago

Its Simpler and works well. Thank you

Fladio Armandika
Guest
Fladio Armandika
22 days 2 hours ago

thank you

Guram Kankava
Guest
Guram Kankava
3 months 10 days ago

Thank you very much. clear and simple. "Everything genius is simple".

Niroz Jung Karki
Guest
Niroz Jung Karki
3 months 12 days ago

How can I use Lambda expression inside update method instead of For Loop.

Niroz Jung Karki
Guest
Niroz Jung Karki
2 months 29 days ago

Thanx Wayne !!

Wayne Covell
Guest
Wayne Covell
3 months 13 hours ago

Please see my latest comment for this answer.

Bharath loka
Guest
Bharath loka
3 months 18 days ago

So if I want to update the id I have to compare all other fields and if all of them matches I can update the id right. Is there any other way to do it

Bharath loka
Guest
Bharath loka
2 months 24 days ago

I got it now we can update the id in the request body itself

Wayne Covell
Guest
Wayne Covell
2 months 27 days ago

Bharath loka you just update using the I'd You want to update, but set a new ID in the topic. Next time you do a search for that first ID, you'll see it no longer exists but the new ID is there

Bharath loka
Guest
Bharath loka
2 months 27 days ago

Wayne Covell you used a lambda expression that is good but what if you want to update the id ?

Wayne Covell
Guest
Wayne Covell
3 months 13 hours ago

Please see my latest comment for this answer.

Irakli Tabagari
Guest
Irakli Tabagari
4 months 20 days ago

Hi,Is Spring "@Service" always "@Singleton" by default??

Sergey Orlovich
Guest
Sergey Orlovich
6 months 8 days ago

You're mistaken in using PUT for update. PUT is used for insert in RESTful api, and POST is for update. Nice tutorial.

Venky V
Guest
Venky V
15 days 11 hours ago

I hope his intention of this demo is how to perform or show differently i.e some basic operations using all request method types. It doesn't mean that they meant for only those actions purpose.

aditya nehra
Guest
aditya nehra
2 months 18 days ago

kar di na chutiyo wali baat

Priten Vora
Guest
Priten Vora
5 months 23 days ago

Actually, it is mentioned in the stackoverflow page that If client decides the URL of the object being created then it is okay to use PUT otherwise we can use POST for resource creation. However using POST for update is not the REST way to go.

Rama41222
Guest
Rama41222
5 months 23 days ago

@sergey lol You must be dreaming

Priten Vora
Guest
Priten Vora
6 months 7 days ago
wpDiscuz