我的删除方法有问题。其他方法都可以,但是删除有问题。它向我显示:不支持请求方法“DELETE”。 我对邮递员的请求是 http://localhost:8080/v1/tasks/1 并带有删除选项。有什么想法吗?
@Service
public class DbService {
@Autowired
private TaskRepository repository;
public void deleteTask(final Long id) throws TaskNotFoundException {
Task task = repository.findById(id).orElseThrow(TaskNotFoundException::new);
repository.deleteById(id);
}
界面
@Repository
public interface TaskRepository extends CrudRepository<Task, Long> {
@Override
void deleteById(Long id);
}
控制器
@DeleteMapping(value = {"taskId"})
public ResponseEntity<String> deleteTask(@PathVariable Long taskId) throws TaskNotFoundException {
service.deleteTask(taskId);
return ResponseEntity.ok("Deleted succesfully" + taskId);
}
您需要:
@DeleteMapping(value = "/{taskId}")
而不是
@DeleteMapping(value = {"taskId"})