我有一个简单的发票系统,我需要创建和更新发票。我正在尝试使用Spring Data Rest,但是根据我从文档中获得的内容,我最终会做很多调用来实现更新。
@Entity
class Article {
@Id
@GeneratedValue
Long ID;
@Basic
String name;
}
@Entity
class Invoice {
@Id
@GeneratedValue
Long ID;
@Basic
String customer;
@OneToMany(cascade=CascadeType.ALL)
List<InvoiceItem> items;
}
@Entity
class InvoiceItem {
@Id
@GeneratedValue
Long ID;
@Basic
double amount;
@ManyToOne
private Article article;
}
我正在使用Spring Data Rest通过这些Spring Data Rest / JPA存储库将此模型公开给我的web fronend
@RepositoryRestResource(collectionResourceRel = "articles", path = "articles")
interface ArticleJPARepository extends JpaRepository<Article, Long> {}
@RepositoryRestResource(collectionResourceRel = "invoices", path = "invoices")
interface InvoiceJPARepository extends JpaRepository<Invoice, Long> {}
@RepositoryRestResource(collectionResourceRel = "invoiceitems", path = "invoiceitems")
interface InvoiceItemJPARepository extends JpaRepository<InvoiceItem, Long> {}
所以,假设我有一个如下所示的更新表单:
我可以做几件事:
我从Spring Rest Docs得到的是我现在需要打几个电话。
PUT /invoices/1
PUT /invoiceitems/<x>/
POST /invoiceitems
然后POST /invoices/1/items
DELETE /invoiceitems/2
,然后删除DELETE /invoices/1/items/<2>
有没有更简单的方法来实现Spring Data Rest的这种更新?