我正在尝试 Spring Data REST 的示例,但是在我的测试中返回的 JSON 对象不返回列名(之前是“PUT”),只是返回对象的链接。有什么问题吗?
Scenario:
实体:“用户”
@Entity
@Data
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String guid;
private String fullName;
private String email;
}
存储库:UserRepository(公开为 REST 服务)
@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends JpaRepository<User, Long> {
}
创建 USER 对象的 REST“PUT”请求:
REST GET 调用以获取用户对象的 JSON 响应(问题)
No id, Guid or email is returned in the JSON response.
最佳答案
删除 lombok 的 @Data 注释使所有基本属性都出现在 JSON 响应中。看起来像是 lombok 的副作用。
关于JSON 不返回 Spring Data REST 中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149426/