【发布时间】:2018-01-07 17:15:00
【问题描述】:
我正在尝试创建一个 RestFul dao Web 服务。非常简单地调用发出 HTTP 请求 CRUD 数据。一切似乎都在工作(我正在使用 curl 创建 HTTP 请求),除了在控制器方法中我没有将 json 数据绑定到 pojo。这是控制器代码:
@PostMapping("/deleteJonTblGet")
public ResponseEntity getDeleteJonTbl(@RequestBody DeleteJonTblId deleteJonTblId)
{
System.out.println("TEST:");
System.out.println(deleteJonTblId.getDJon());
DeleteJonTbl deleteJonTbl = deleteJobTblDao.findById(1);
if (deleteJonTbl == null)
{
return new ResponseEntity("No Customer found for ID ", HttpStatus.NOT_FOUND);
}
return new ResponseEntity(deleteJonTbl, HttpStatus.OK);
}
这里是 POJO: 公共类 DeleteJonTblId 实现 java.io.Serializable {
private String DJon;
private String DReturn;
private Integer DCtr;
private String DRecdat;
private String DRectime;
public DeleteJonTblId()
{
}
public DeleteJonTblId(String DJon, String DReturn, Integer DCtr, String DRecdat, String DRectime)
{
this.DJon = DJon;
this.DReturn = DReturn;
this.DCtr = DCtr;
this.DRecdat = DRecdat;
this.DRectime = DRectime;
}
@Column(name = "D_JON", length = 12)
public String getDJon()
{
return this.DJon;
}
public void setDJon(String DJon)
{
this.DJon = DJon;
}
@Column(name = "D_RETURN", length = 2)
public String getDReturn()
{
return this.DReturn;
}
public void setDReturn(String DReturn)
{
this.DReturn = DReturn;
}
@Column(name = "D_CTR", precision = 7, scale = 0)
public Integer getDCtr()
{
return this.DCtr;
}
public void setDCtr(Integer DCtr)
{
this.DCtr = DCtr;
}
@Column(name = "D_RECDAT", length = 8)
public String getDRecdat()
{
return this.DRecdat;
}
public void setDRecdat(String DRecdat)
{
this.DRecdat = DRecdat;
}
@Column(name = "D_RECTIME", length = 6)
public String getDRectime()
{
return this.DRectime;
}
public void setDRectime(String DRectime)
{
this.DRectime = DRectime;
}
public boolean equals(Object other)
{
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof DeleteJonTblId))
return false;
DeleteJonTblId castOther = (DeleteJonTblId) other;
return ((this.getDJon() == castOther.getDJon())
|| (this.getDJon() != null && castOther.getDJon() != null && this.getDJon().equals(castOther.getDJon())))
&& ((this.getDReturn() == castOther.getDReturn()) || (this.getDReturn() != null
&& castOther.getDReturn() != null && this.getDReturn().equals(castOther.getDReturn())))
&& ((this.getDCtr() == castOther.getDCtr()) || (this.getDCtr() != null && castOther.getDCtr() != null
&& this.getDCtr().equals(castOther.getDCtr())))
&& ((this.getDRecdat() == castOther.getDRecdat()) || (this.getDRecdat() != null
&& castOther.getDRecdat() != null && this.getDRecdat().equals(castOther.getDRecdat())))
&& ((this.getDRectime() == castOther.getDRectime()) || (this.getDRectime() != null
&& castOther.getDRectime() != null && this.getDRectime().equals(castOther.getDRectime())));
}
public int hashCode()
{
int result = 17;
result = 37 * result + (getDJon() == null ? 0 : this.getDJon().hashCode());
result = 37 * result + (getDReturn() == null ? 0 : this.getDReturn().hashCode());
result = 37 * result + (getDCtr() == null ? 0 : this.getDCtr().hashCode());
result = 37 * result + (getDRecdat() == null ? 0 : this.getDRecdat().hashCode());
result = 37 * result + (getDRectime() == null ? 0 : this.getDRectime().hashCode());
return result;
}
}
这是卷曲:
curl --libcurl C:\Development\test.log -i -X POST -H "Content-Type: application/json" -d "{\"DJon\":\"a\",\"DReturn \":\"a\",\"DCtr\":1,\"DRecdat\":\"a\",\"DRectime\":\"a\"}" http://localhost:8080/taaDaoWS/deleteJonTblGet
控制器方法已执行,但 deleteJonTblId 对象具有所有空值。任何帮助将不胜感激。
【问题讨论】:
标签: spring rest web-services model-view-controller