Spring 数据剩余绑定
Spring Data Rest Binding
我正在尝试使用 Spring-Data-Rest,但我认为 Spring 没有绑定我通过 Post 给出的 body object。
我的域 class 看起来像:
@Entity
@EqualsAndHashCode
@ToString
public class Rendite{
@Id @GeneratedValue Long id;
double jahresNettoMiete;
public Rendite(){}
}
@RepositoryRestResource(collectionResourceRel = "renditen", path = "renditen")
public interface RenditeRepositoryextends CrudRepository<Rendite, Long> {}
通过 Get 调用工作正常:
调用 POST 保存实体也会调用应用程序,但它不会将值绑定到 属性:
您的实体似乎缺少 getters(和可选的)setter。
为相关字段添加 public getter 应该允许序列化 和 反序列化。
在此处进一步了解此内容:
http://www.baeldung.com/jackson-field-serializable-deserializable-or-not
Unintuitively, the getter also makes the private field deserializable
as well – because once it has a getter, the field is considered a
property.
您可以按照文章中概述的各种方式控制 serialization/deserialization。
另一种不添加 getter 的方法是使用:
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
如以下示例 4.5 中所述:
我正在尝试使用 Spring-Data-Rest,但我认为 Spring 没有绑定我通过 Post 给出的 body object。
我的域 class 看起来像:
@Entity
@EqualsAndHashCode
@ToString
public class Rendite{
@Id @GeneratedValue Long id;
double jahresNettoMiete;
public Rendite(){}
}
@RepositoryRestResource(collectionResourceRel = "renditen", path = "renditen")
public interface RenditeRepositoryextends CrudRepository<Rendite, Long> {}
通过 Get 调用工作正常:
调用 POST 保存实体也会调用应用程序,但它不会将值绑定到 属性:
您的实体似乎缺少 getters(和可选的)setter。
为相关字段添加 public getter 应该允许序列化 和 反序列化。
在此处进一步了解此内容:
http://www.baeldung.com/jackson-field-serializable-deserializable-or-not
Unintuitively, the getter also makes the private field deserializable as well – because once it has a getter, the field is considered a property.
您可以按照文章中概述的各种方式控制 serialization/deserialization。
另一种不添加 getter 的方法是使用:
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
如以下示例 4.5 中所述: