How would one implement a simple deletion Rest request in the Controller suchh that I can delete both by id and by name?
I have attempted to emmulate the This StackOverflow question but with no luck so far. Please see code below.
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void removeStudent(@PathVariable("id") int id){
studentService.removeStudent(id);
}
@RequestMapping(method = RequestMethod.DELETE)
public void removeStudent(@RequestParam(value="name") String name){
studentService.removeStudent(name);
}
Deleting by id works perfectly, however when attempting to delete by name - nothing works.
I attempted to DELETE just the specific record for a name with the following as per the previous question mentioned:
http://localhost:8080/students?name=FOUR
But it brings EVERYTHING back...
EDIT
I believe me code for removing the entry is incorrect.
I am attempting to remove an entry from a HashMap:
private static Map<Integer, Student> students;
static {
students = new HashMap<Integer, Student>(){
{
// int id, String name, String school, String course
put(1, new Student(1,"Adam", 24, "School1", "Physics"));
put(2, new Student(2,"Luke", 27, "School1", "Electronics"));
put(3, new Student(3,"Mick", 56, "School1", "Trains"));
}
};
}
@Override
public void removeStudent(String name) { this.students.remove(name); }