我从http服务获得空响应。我在spring boot中的service方法正确返回了响应数据,但在角度显示为null。
这是我的角度方法:
this.httpService.findById(UrlDetails.$getPymentInfoResponseUrl, request).subscribe((response) => {
debugger;
if (response.responseCode == 200) {
let PaymentData=response.responseData;
let Payment = response.responseData;
if(this.payment.paymentMethod == 'CREDIT_CARD'){
this.jobPaymentForm.get('paymentMethod').setValue('CREDIT_CARD');
this.jobPaymentForm.get('cardHolderName').setValue(this.payment.creditCardPayment.cardHolderName);
this.jobPaymentForm.get('cardNumber').setValue(this.payment.creditCardPayment.cardNumber);
this.jobPaymentForm.get('expirationMonth').setValue(this.payment.creditCardPayment.expirationMonth);
this.jobPaymentForm.get('expirationYear').setValue(this.payment.creditCardPayment.expirationYear);
this.paymentType1 = false;
this.paymentType2 = true;
this.paymentMehodSelect=false;
}
这是http服务:
findById(url:string, value:any):Observable < any > {
let headers = new Headers( {'Content-Type':'application/json'});
let options = new RequestOptions( {headers:headers });
return this.http.post(url, value, options).map(this.extractData);
}
这是用于将请求的数据发送回angular的spring boot方法:
public ResponseEntity<BaseEntitiesResponse<Payment>> getPaymentInfo(Payment payment) {
System.out.println("---->"+payment);
logger.debug("entering inside getPaymentInfo method for {} ",payment.getClientId());
logger.debug("entering inside getPaymentInfo method for {} ",payment.getOrderId());
BaseEntitiesResponse<Payment> findPaymentResponse = new BaseEntitiesResponse<>();
if (payment == null) {
findPaymentResponse.setInvalidRequestParamResponse();
return new ResponseEntity<BaseEntitiesResponse<Payment>>(findPaymentResponse, HttpStatus.OK);
}
List<Payment> record = paymentRepository.findPaymentMethodByClientId(payment.getClientId());
List<Payment> record1 = paymentRepository.findPaymentByClientIdAndOrderId(payment.getClientId(),payment.getOrderId());
logger.debug("Record object : ",record1);
if (record == null || record.isEmpty()) {
findPaymentResponse.setRecordNotFoundResponse();
return new ResponseEntity<BaseEntitiesResponse<Payment>>(findPaymentResponse, HttpStatus.OK);
}
findPaymentResponse.setRecordFoundResponse(record1);
return new ResponseEntity<BaseEntitiesResponse<Payment>>(findPaymentResponse, HttpStatus.OK);
}
此方法返回正确的响应。