所以我使用SpringDataRest构建一个REST api,Get和Post都在工作,但我不知道PUT有什么问题。
这是我使用的实体:
@Entity
@Table(name = "companies")
public class Company {
@Id
@Column(name="CompanyId", nullable=false, unique=true)
private String companyId;
@Column(name="Name", nullable=false)
private String name;
@Column(name="ContactName", nullable=false)
private String contactName;
@Column(name="ContactSurName")
private String contactSurname;
@Column(name="ContactEmail", nullable=false)
private String contactEmail;
@Column(name="ContactPhone")
private String contactPhone;
@Column(name="Enabled", nullable=false)
private String enabled;
@Column(name="Logo")
private String logo;
@Column(name = "CreationDate", columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@Column(name = "LastUpdateDate", columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
//Region Constructors
private Company(){}
public Company(String companyId, String name, String contactName, String contactSurname, String contactEmail, String contactPhone,
String enabled){
this.companyId = companyId;
this.name = name;
this.contactName = contactName;
this.contactSurname = contactSurname;
this.contactEmail = contactEmail;
this.contactPhone = contactPhone;
this.enabled = enabled;
this.creationDate = new Date();
this.lastUpdateDate = new Date();
}
//EndRegion
//Region Getters & Setters
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getContactSurname() {
return contactSurname;
}
public void setContactSurname(String contactSurname) {
this.contactSurname = contactSurname;
}
public String getContactEmail() {
return contactEmail;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String contactPhone) {
this.contactPhone = contactPhone;
}
public String getEnabled() {
return enabled;
}
public void setEnabled(String enabled) {
this.enabled = enabled;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastUpdateDate() {
return lastUpdateDate;
}
public void setLastUpdateDate(Date lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}
//EndRegion
}
执行此请求时:
我收到了这个回复:
{
"cause": {
"cause": null,
"message": "No content to map due to end-of-input\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1130374; line: 1, column: 0]"
},
"message": "Could not read an object of type class com.wipma.application.domain.Company from the request!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1130374; line: 1, column: 0]"
}
我无法弄清楚什么是错的,我怀疑它与某些字段映射有关,但无法解决它。
提前致谢