我正在更新数据库中的一个布尔列,以通过一个有角度的前端按钮批准客户帐户。发送请求后,控制器将引发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);
}
我真的不知道我在做什么错。我如何解决它并了解错误原因?
答案 0 :(得分:0)
在您发布的JSON中,以下属性与godoc -goroot=/some/folder -http=:6060
不匹配。请相应更改
@RequestBody Customer