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

时间:2019-01-30 20:55:24

标签: spring-boot ionic3

当通过离子调用此API时,我正在通过spring-boot创建h RestApi服务,这给我一个错误DELETE http://localhost:8080/patientsundefined 404(),这是我的代码:  错误HttpErrorResponse {标头:HttpHeaders,状态: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 个答案:

答案 0 :(得分:0)

首先,请按如下所示修改您调用服务的URL:
this.http.delete(this.url+'/'+item.Id, httpOptions)由于您已定义删除服务的URI为patients/{id}

第二,似乎您传递给服务的ID是未定义的,您还应该检查一下。

祝你好运!