Как исправить: отсутствует обязательное тело запроса: [org.springframework.http.converter.HttpMessageNotReadableException:] - PullRequest
0 голосов
/ 28 мая 2019

Я обновляю логическую колонку в моей базе данных для утверждения учетных записей клиентов с помощью угловой интерфейсной кнопки.Как только я отправляю свой запрос, мой контроллер выдает ошибку Resolved [org.springframework.http.converter.HttpMessageNotReadableException:Required request body is missing:.Изо всех сил пытался отладить его и был бы признателен за некоторые рекомендации по этому вопросу.

На данный момент мой код выглядит следующим образом:

контроллер:

@RequestMapping(value = "/customers/afisapprove", method = 
RequestMethod.POST)
public ResponseEntity<?> updCustAfisStatus(@RequestBody Customer 
customer) throws Exception {
    try {
        System.out.println("account no##" + 
customer.getAccountNumber());
        System.out.println("afis no##" + 
customer.getAfisStatus());
        System.out.println("afis id##" + customer.getId());

        int approveCust = 
customerService.approveAfisCustomer(customer.isActive());

        // begin saving audit trail
        auditTrail = new AuditTrail((customer.getCreatedBy()), "Approved Customer " + customer.getFullName(), date,
                "Approve Customer");
        auditTrailService.saveAuditTrail(auditTrail);
        System.out.println("approved##" + approveCust);
        if (approveCust > 0) {
            // int trash = customerService.trashAfisBio(customer.getId());
            // if(trash <= 0 ) {
            // return new ResponseEntity<>(new CustomResponse(CustomResponse.APIV,
            // 200,false,
            // "failed to trash raw images"),HttpStatus.OK);
            // }
            return new ResponseEntity<>(
                    new CustomResponse(CustomResponse.APIV, 200, true, "customer approved successfully"),
                    HttpStatus.OK);

        }
        return new ResponseEntity<>(
                new CustomResponse(CustomResponse.APIV, 200, false, "failed to approve customer"), HttpStatus.OK);
    } catch (Exception e) {
        return new ResponseEntity<>(
                new CustomResponse(CustomResponse.APIV, 200, false, "Server error processing request"),
                HttpStatus.OK);
    }
}

класс сущности:

@Entity
@Table(name="Customerr")
public class Customer extends BaseModel implements Serializable{

    private static final long serialVersionUID = 1L;

    @Column(name="account_number")
    private String accountNumber;

    @Column(name="teller_id")
    private String tellerId;

    @Column(name="active")
    private boolean active=false;

    @Column(name="branchId")
    private String branchId;

    @Column(name="dateOfBirth")
    private String dateOfBirth;

    @Column(name ="emailAddress")
    private String emailAddress;

    @Column(name="fullName")
    private String fullName;

    @Column(name="gender")
    private String gender;

    @Column(name="idNumber")
    private String idNumber;

    @Column(name="phoneNumber")
    private String phoneNumber;

    @Column(name="postalAddress")
    private String postalAddress;

    @Column(name="postalCode")
    private String postalCode;

    @Column(name="postalTown")
    private String postalTown;

    @Column(name="created_on",columnDefinition="datetime default getDate()")
    private Date createdOn;

    @Column(name="afisid")
    private String pbuno;

    @Column(name="userProfile",columnDefinition="varchar(max)")
    private String profilePic;

    @Column(name="verified")
    private String approved;

    @Column(name="verified_by")
    private int approvedBy;

    @Column(name="created_by", nullable = false)
    private int createdBy;

    @Column(name="verified_on")
    private Date approvedOn;

    @Column(name="afis_status")
    private String afisStatus;

    @OneToMany(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name="customer_id")
    private List<CustomerBio> bios;

    @OneToMany(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name="customer_id")
    private List<RawImages> raws;

    public Customer() {
        super();

    }

    public Customer(String accountNumber, String tellerId, boolean active, String branchId, String dateOfBirth, String emailAddress,
            String fullName, String gender, String idNumber, String phoneNumber, String postalAddress,
            String postalCode, String postalTown, Date createdOn, String pbuno, String profilePic, String approved,
            int approvedBy, Date approvedOn, List<CustomerBio> bios,String afisStatus,List<RawImages> raws,int createdBy) {
        super();
        this.tellerId = tellerId;
        this.accountNumber = accountNumber;
        this.active = active;
        this.branchId = branchId;
        this.dateOfBirth = dateOfBirth;
        this.emailAddress = emailAddress;
        this.fullName = fullName;
        this.gender = gender;
        this.idNumber = idNumber;
        this.phoneNumber = phoneNumber;
        this.postalAddress = postalAddress;
        this.postalCode = postalCode;
        this.postalTown = postalTown;
        this.createdOn = createdOn;
        this.pbuno = pbuno;
        this.profilePic = profilePic;
        this.approved = approved;
        this.approvedBy = approvedBy;
        this.approvedOn = approvedOn;
        this.bios = bios;
        this.afisStatus=afisStatus;
        this.raws=raws;
        this.createdBy=createdBy;
    }

    public int getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(int createdBy) {
        this.createdBy = createdBy;
    }

    public String getAfisStatus() {
        return afisStatus;
    }

    public void setAfisStatus(String afisStatus) {
        this.afisStatus = afisStatus;
    }

    public String getApproved() {
        return approved;
    }

    public void setApproved(String approved) {
        this.approved = approved;
    }

    public int getApprovedBy() {
        return approvedBy;
    }

    public void setApprovedBy(int approvedBy) {
        this.approvedBy = approvedBy;
    }

    public Date getApprovedOn() {
        return approvedOn;
    }

    public void setApprovedOn(Date approvedOn) {
        this.approvedOn = approvedOn;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getTellerId() {
        return tellerId;
    }

    public void setTellerRef(String tellerId) {
        this.tellerId = tellerId;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getBranchId() {
        return branchId;
    }

    public void setBranchId(String branchId) {
        this.branchId = branchId;
    }

    public String getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getPostalAddress() {
        return postalAddress;
    }

    public void setPostalAddress(String postalAddress) {
        this.postalAddress = postalAddress;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getPostalTown() {
        return postalTown;
    }

    public void setPostalTown(String postalTown) {
        this.postalTown = postalTown;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

//    @PrePersist
    public void setCreatedOn() {
        this.createdOn = new Date();
    }

//    public List<CustomerBio> getBios() {
//        return bios;
//    }
//
//    public List<RawImages> getRaws() {
//        return raws;
//    }
//
//    public void addBio(CustomerBio bio) {
//        bio.setCustomer(this);
//        bios.add(bio);
//    }
//
//    public void addRaw(RawImages raw) {
//        raw.setCustomer(this);
//        raws.add(raw);
//    }

    public String getPbuno() {
        return pbuno;
    }

    public void setPbuno(String pbuno) {
        this.pbuno = pbuno;
    }

    public int getColumnCount() {
        return 7;
    }

    public String getProfilePic() {
        return profilePic;
    }

    public void setProfilePic(String profilePic) {
        this.profilePic = profilePic;
    }

    @Override
    public String toString() {
        return "Customer{" + "accountNumber=" + accountNumber + ", fullName=" + fullName + ", dateOfBirth=" + dateOfBirth + '}';
    }
}

json:

       {
            "Id": 13,
            "name": "KABALIISA SCOVIA",
            "afisid": "PBU433369",
            "active": false,
            "branchId": "1",
            "dateOfBirth": "2019-03-07",
            "emailAddress": "johndoe@gmail.com",
            "fullName": "Nelson",
            "gender": "Male",
            "idNumber": "90785634",
            "phoneNumber": "0721234567",
            "postalAddress": "8445",
            "postalCode": "00200",
            "postalTown": "Mombasa",
            "userProfile": "",
            "createdBy": 0
        }, 

Служба:

public int approveAfisCustomer(boolean active) {
        // TODO Auto-generated method stub
        return Customerrepository.approveAfisCustomer(active);
    }

Я действительно не знаю, что я делаю неправильно.Как я могу это исправить и понять причину ошибки?

1 Ответ

0 голосов
/ 28 мая 2019

В опубликованном вами JSON следующие атрибуты не соответствуют @RequestBody Customer .Измените соответственно

  {
            "Id": 13,
            "name": "KABALIISA SCOVIA",
            "afisid": "PBU433369",

            "userProfile": "",

        },
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...