Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何使用traverson将新数据发布到Spring数据Rest服务?_Angularjs_Spring_Spring Boot_Spring Data Rest_Spring Hateoas - Fatal编程技术网

Angularjs 如何使用traverson将新数据发布到Spring数据Rest服务?

Angularjs 如何使用traverson将新数据发布到Spring数据Rest服务?,angularjs,spring,spring-boot,spring-data-rest,spring-hateoas,Angularjs,Spring,Spring Boot,Spring Data Rest,Spring Hateoas,我在网上找不到任何关于如何将带有traverson的新实体发布到SpringDataREST服务的示例。有人有帮助链接吗 在尝试发送此数据时,我确实被卡住了: { billingService: "http://localhost:8080/api/v1/billingServices/1", invoicingPartyId: "xyz", mandator: "http://localhost:8080/api/v1/mandators/1" } 使

我在网上找不到任何关于如何将带有traverson的新实体发布到SpringDataREST服务的示例。有人有帮助链接吗

在尝试发送此数据时,我确实被卡住了:

{           
   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问题的任何想法,当然我可以使用简单的$http或$resource,但我想使用traverson)

顺便说一句,我正在使用: (3.1.1)和 (4.1.1)和 Spring Boot 1.4.1.BUILD-SNAPSHOT

谢谢,, 基督教徒


附言:为什么没有traverson标签?没有人使用它吗?

如果我直接将数据发布到给定的url,它将与traverson一起工作:
traverson.from(BasePath+'/billingServiceClient')。withRequestOptions({headers:{'Content-Type':'application/json'})。post(billingServiceClient).
但这是正确的方法吗?
{
  "_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"
    }
  }
}