Pavindu
Pavindu

Reputation: 3113

Send RequestParam to Spring Boot Server in Axios

I have a controller method in my Spring Boot app which takes an argument from @RequestParam. I'm sending it using Axios, but every time the server responds with the following warning and the function doesn't get executed.

Required long parameter 'task_id' is not present]

axios request

axios.delete("/task-asignee/" + props.userId, null, {
     params: {
       task_id: props.taskId,
     },
   })
   .then(res => {
      props.onRemove();
    })
   .catch(err => console.log(err));

Spring boot controller method

@DeleteMapping("/task-asignee/{userId}")
public void removeTaskAssignee(@RequestParam("task_id") long taskId,@PathVariable long userId) {
    TaskAsigneeKey tak = new TaskAsigneeKey(userId,taskId);
    TaskAsignee ts = taskAsRepository.findById(tak);
    taskAsRepository.delete(ts);
}

Upvotes: 0

Views: 3594

Answers (1)

A.khalifa
A.khalifa

Reputation: 2496

Try this

axios.delete("/task-asignee/" + props.userId, {
     { params: { task_id: props.taskId} ,
   })
   .then(res => {
      props.onRemove();
    })
   .catch(err => console.log(err));

Upvotes: 2

Related Questions