我可以使用Spring Data Rest进行PUT但不能执行POST吗?

问题描述 投票:0回答:1

我有两个简单的实体,例如:

public class Agent extends BasedEntity {

    private String firstname;

    private String lastname;

    @ManyToOne
    @JoinColumn(name="agency_id", nullable=true)
    Agency agency;
}

public class Agency extends BasedEntity {

    private String name;

    private String address;

    @OneToMany(mappedBy="agency")
    private Set<Agent> agents;
}

@RepositoryRestResource
public interface AgencyRespository extends JpaRepository<Agency, Long> {
}


@RepositoryRestResource
public interface AgentsRespository extends JpaRepository<Agent, Long> {
}

当我使用]进行PUT时>

https://localhost:8080/api/v1/agents/64/agency
body:https://localhost:8080/api/v1/agencies/50

它通过了,但是如果我对[POST]做过

https://localhost:8080/api/v1/agents/64/agency
body:https://localhost:8080/api/v1/agencies/50

我得到一个

org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported

我有两个简单的实体,例如:公共类Agent扩展BasedEntity {private String firstname;私有字符串姓氏; @ManyToOne @JoinColumn(name =“ agency_id”,nullable = ...

spring rest spring-data spring-data-rest hateoas
1个回答
0
投票

您正在使用旧版本的Spring Data Rest。从2.3.x开始允许POST。

© www.soinside.com 2019 - 2024. All rights reserved.