Reputation: 1
I have been trying CRUD Operation for my spring boot.
I have to delete the row by given name in delete()
method. I need some guidance to get this working. I debugged the code but it returns 500 error on Postman. What did I do wrong?
public String deletedList(String name) {
List <Grocery> v = rss.findAll();
for(Grocery gig: v) {
while(gig != null) {
if(gig.getName().equals(name)) {
rss.deleteAll();`your text`
return "success";
}}
}
for(Grocery f : v) {
if(f.getName() != name) {
throw new DeleteException("Not Found");
}}
return "not found";
}
Upvotes: -1
Views: 61
Reputation: 1
Remove the while loop and replace it with an if condition. and Use rss.delete(grocery) to delete the matched item instead of rss.deleteAll(). This should work as expected.
Upvotes: 0