Search code examples
javaspringspring-bootresponse

ResponseEntity redirecting to a new page, while I want it to remain in the same page


When I am pressing delete button I am redirected to the link attached to this button while I want be the same page while I use ResponseEntity. Here is the button:

<td><a type="button" class="btn btn-warning" href="/delete-todo?id=${todo.id}">DELETE</a></td>

Here is my controller:

@RequestMapping(value="/delete-todo")
public ResponseEntity<Void> deleteTodo(@RequestParam int id){
    todoService.delete(id);
    return ResponseEntity.ok().build();
}

After pressing delete button

The delete button

Can anyone tell what I'm doing wrong with ResponseEntity.


Solution

  • Simply return remove redirect should work:

    @RequestMapping(value="/delete-todo")   
    public String deleteTodo(@RequestParam int id){         
       todoService.delete(id);      
       return "/todo-list";     
    }