首页 > 解决方案 > 来自 http 服务的空响应

问题描述

我收到来自 http 服务的空响应。我在 Spring Boot 中的服务方法正确返回响应数据,但在角度上它显示为空。

这是我的角度方法:

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); 

}

这是将请求的数据发送回角度的弹簧启动方法:

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);
}

此方法返回正确的响应。

标签: angularspring-boot

解决方案


推荐阅读