删除 http://localhost:8080/患者未定义 404()

Posted

技术标签:

【中文标题】删除 http://localhost:8080/患者未定义 404()【英文标题】:DELETE http://localhost:8080/patients undefined 404 () 【发布时间】:2019-06-24 06:04:01 【问题描述】:

我正在通过 spring-boot 创建 h RestApi 服务,当通过 ionic 调用此 API 时,它给了我一个错误 DELETE http://localhost:8080/patientsundefined 404 (),这是我的代码: 错误 HttpErrorResponse headers: HttpHeaders, status: 404, statusText: "OK", url: "http://localhost:8080/patientsundefined", ok: false...

#ts
deletePatient(Patient_add:Patient)

    this.databasedata.deletePatient(Patient_add).subscribe(

      (data:any)=>

        if(data.affectedRows==1)
           let mes=this._toast.create(
            message:'Task Deleted Successfully',
            duration:2000,
            position:'bottom'
          );

          this.AllPatient.splice(this.AllPatient.indexOf(Patient_add),1);
          mes.present();
        

        else
          let mes=this._toast.create(
            message:'Error in deleting task',
            duration:2000,
            position:'bottom'
          );
          mes.present();
        
      
  ,)



#.html
<ion-content padding>

  <ion-list inset>
    <ion-input type="hidden" placeholder="id" autofocus="" [(ngModel)]="id" ></ion-input>
    <ion-input placeholder="Write here your name"  [(ngModel)]="name"  ></ion-input>
    <ion-input placeholder="Write here your doctor name"  [(ngModel)]="doctor_name"  ></ion-input>
    <ion-input placeholder="Write here your Hosptial or clinic name"  [(ngModel)]="hospital_clinic"  ></ion-input>
    <ion-input placeholder="Write date or your prescription?"  [(ngModel)]="date" ></ion-input>

<ion-buttons>
  <button (click)= "addPatient()"> ADD</button>
</ion-buttons>

    <ion-item *ngFor="let AP of AllPatient" >

      <ion-label [ngClass]="'donestatus': AP.Status=='done','pendingstatus':AP.Status=='pending'" >AP.name AP.doctor_name AP.hospital_clinic AP.date</ion-label>
      <ion-icon item-right (click)="deletePatient(AP)"  ios="ios-trash" md="md-trash"></ion-icon>
      <ion-icon item-right (click)="updatePatient(AP)"  ios="ios-color-wand" md="md-color-wand"></ion-icon>
      <!--<ion-icon name="trash" ios="ios-trash" md="md-trash"></ion-icon>-->
    </ion-item>
  </ion-list>


</ion-content>


#provider.ts
deletePatient(item:Patient)
    return this.http.delete(this.url+item.Id, httpOptions)

  

#.Controller(Spring-boot)


@RequestMapping(value = "patients/id", method = RequestMethod.DELETE)
    public ResponseEntity<Void> delete(@PathVariable("id") int id) 
        try 
            service.deletePatient(id);
            return new ResponseEntity<Void>(HttpStatus.OK);
         catch (Exception e) 
            return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
        

    

【问题讨论】:

【参考方案1】:

首先,请将您调用服务的 URL 修改为:this.http.delete(this.url+'/'+item.Id, httpOptions),因为您定义了删除服务的 URI 为patients/id

其次,您传递给服务的ID似乎未定义,您也应该检查一下。

祝你好运!

【讨论】:

以上是关于删除 http://localhost:8080/患者未定义 404()的主要内容,如果未能解决你的问题,请参考以下文章

Java Web报错: GET http://localhost:8080/ 404 (Not Found)

CORS 策略已阻止从源“http://localhost:4200”访问“http://localhost:8080/BeginSignup”获取

http://localhost:8080打开tomcat主页的原理是啥

运行时出错:http://localhost:8080

CORS 策略已阻止从源“http://localhost:3000”访问“http://localhost:8080/demo/getAll”获取

带有 Angular 的 Spring Boot。从源“http://localhost:4200”访问“http://localhost:8080/”的 XMLHttpRequest 已被 CORS