1
我有以下方法REST类型:弹簧RequestBody映射映射的所有属性,以空值
@RequestMapping(value = "/budgetLines",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public void create(@RequestBody BudgetLine budgetLine) {
System.out.println("Before Persisting in the repository " + budgetLine);
budgetLineRepository.save(budgetLine);
}
我'消耗的网络应用程序内该方法中,我使用网络分析工具(在web developper工具检查铬))对象发送的对象是有效的(除id以外的所有属性都设置了有效值),但是传递给存储库的对象只包含空属性。
这里有一个例子体:
{
"Name":"testLabel",
"Label":"testName",
"AnnualBudget":9000
}
类BudgetLine定义如下:
@Entity
@Table(name = "T_BUDGETLINE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class BudgetLine implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "label")
private String Label;
@Column(name = "name")
private String Name;
@Column(name = "annual_budget", precision=10, scale=2)
private BigDecimal AnnualBudget;
@OneToMany(mappedBy = "budgetLine")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Report> reportss = new HashSet<>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLabel() {
return Label;
}
public void setLabel(String Label) {
this.Label = Label;
}
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public BigDecimal getAnnualBudget() {
return AnnualBudget;
}
public void setAnnualBudget(BigDecimal AnnualBudget) {
this.AnnualBudget = AnnualBudget;
}
public Set<Report> getReportss() {
return reportss;
}
public void setReportss(Set<Report> Reports) {
this.reportss = Reports;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BudgetLine budgetLine = (BudgetLine) o;
if (id != null ? !id.equals(budgetLine.id) : budgetLine.id != null) return false;
return true;
}
@Override
public int hashCode() {
return (int) (id^(id >>> 32));
}
@Override
public String toString() {
return "BudgetLine{" +
"id=" + id +
", Label='" + Label + "'" +
", Name='" + Name + "'" +
", AnnualBudget='" + AnnualBudget + "'" +
'}';
}
public BudgetLine() {
}
}
用请求正文中的参数,'name','label'和'annualBudget'的小写第一个字母来尝试。 –
哇,这是它谢谢你,永远不会跨越我的想法 – mteffaha
太棒了,我已经添加它作为一个答案,因为它帮助。 –