我无法在线找到有关如何使用traverson将新实体发布到Spring Data Rest Service的任何示例。有人有帮助链接吗?
我在尝试发送此数据时确实遇到了问题:
{
billingService: "http://localhost:8080/api/v1/billingServices/1",
invoicingPartyId: "xyz",
mandator: "http://localhost:8080/api/v1/mandators/1"
}
使用此JavaScript代码:
this.newBillingServiceClient = function(billingServiceClient) {
var api = traverson
.from(BasePath)
.jsonHal()
.withRequestOptions({
headers: {
'Content-Type': 'application/json'
}
});
return api.follow('billingServiceClients')
.post(billingServiceClient).result.then(function(doc) {
console.log(doc);
}, function(err) {
console.log(err);
});
};
这是我的实体:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "BILLING_SERVICE_ID", "MANDATOR_ID" }) })
@Data
@EntityListeners(AuditingEntityListener.class)
public class BillingServiceClient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@OneToOne(optional = false)
private Mandator mandator;
@OneToOne(optional = false)
private BillingService billingService;
@NotEmpty
private String invoicingPartyId;
@CreatedBy
private String createdBy;
@CreatedDate
private Date createdDate;
@LastModifiedBy
private String modifiedBy;
@LastModifiedDate
private Date lastModifiedDate;
}
和我的存储库:
@RepositoryRestResource(collectionResourceDescription = @Description("Rechnungsservicemandant"))
public interface BillingServiceClientRepository extends CrudRepository<BillingServiceClient, Long> {
}
Traverson仅在跟踪链接时发送GET请求,但没有发送数据的帖子。
以下是对BasePath的响应,可能会有所帮助?!
{
"_links": {
"billingServices": {
"href": "http://localhost:8080/api/v1/billingServices"
},
"mandators": {
"href": "http://localhost:8080/api/v1/mandators"
},
"billingServiceClients": {
"href": "http://localhost:8080/api/v1/billingServiceClients"
},
"profile": {
"href": "http://localhost:8080/api/v1/profile"
}
}
}
一个简单的链接到一个有用的在线资源就足够了......(或任何关于如何用traverson解决我的问题的想法,当然我可以使用简单的$ http或$ resource但我想使用traverson)。
顺便说一下。我在用: https://github.com/basti1302/traverson-angular(3.1.1)和 https://github.com/basti1302/traverson-hal(4.1.1)和 Spring Boot 1.4.1.BUILD-SNAPSHOT。
谢谢你, 基督教
P.S。:为什么没有traverson标签?没人用吗???