What do I need to implement in order to create multiple records in my database with a single HTTP request?
I have a small web application using SpringDataRest and JPA / Hibernate in which I can create resources with such requests:
curl -XPUT -H"Content-Type: application/json; charset utf-8"\ -d'{"id":"1","type":"test"}'\ http://localhost:8080/test/items/1
Instead, I would like to do something like:
curl -XPUT -H"Content-Type: application/json; charset utf-8"\ -d'[{"id":"1","type":"test1"},{"id":"2","type":"test2"}]'\ http://localhost:8080/test/items/
The corresponding repository is as follows:
@RestResource(path = "items", rel = "items") public interface ItemRepository extends PagingAndSortingRepository<Item, String> { }
Used by Bean:
@Entity @XmlRootElement(name = "page") @Table(name="page") public class Item { @Id @Column(name="id") private String id; @Column(name="type") private String type; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getType() { return type; } public void setType(String type) { this.type = type; } }
java spring-data-rest hibernate jpa
Andreas
source share