小编Dou*_*ley的帖子

Spring引导休息服务,如何让它将链接封装为属性?

这里的第一个问题所以要温柔:)

我有一个JPA项目,我希望将其公开为REST.到目前为止我做到了这一点:

我的实体:

@Entity
public class SignUpSheet {
    @Id
    @GeneratedValue
    private Long id;

    @Column
    private String name;

    @Column
    private String description;

    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTime;

    @ManyToOne
    private User parent;

    @OneToMany
    private List<Volunteer> volunteers;

    //getter and setters
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,我打电话给我的pom添加了spring-boot-starter-data-rest,现在我得到了一个服务.这是我回来的JSON.

http://localhost:8080/api-0.1.0/signUpSheets/1

{
  "name": "Auction",
  "description": "My First Sign Up Sheet",
  "dateTime": "2015-04-22T03:47:12.000+0000",
  "volunteers": [
   {
    "role": "Bringing stuff",
    "comments": "I have comments!"
   }
   ], 
  "endpoint": "/signUpSheets",
  "_links": {
    "self": {
      "href": "http://localhost:8080/api-0.1.0/signUpSheets/1"
    },
    "parent": {
      "href": "http://localhost:8080/api-0.1.0/signUpSheets/1/parent"
    },
    "user": {
      "href": …
Run Code Online (Sandbox Code Playgroud)

spring-data-jpa spring-data-rest spring-hateoas spring-boot

6
推荐指数
1
解决办法
1244
查看次数