BackendIdConverter无法解析为一种类型

时间:2019-02-11 12:33:44

标签: java spring rest

在使用复合主键创建新实体时遇到问题。我在这篇文章Spring Data Rest @EmbeddedId cannot be constructed from Post Request中读到,这个问题可能是 使用BackendIdConverter解决。 首先,我不了解此类的用法以及它如何将uri转换为id。谁能给我一个例子 其次,当我尝试编写扩展BackendIdConverter的类时,出现错误,提示它无法解析为类型。您能帮我解决这个问题吗

@Entity
@Table(name = "booking_routes")

The entity class
public class BookingRoute extends ResourceSupport implements Serializable, Comparable<BookingRoute> {
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private BookingRouteId pk=new BookingRouteId();
    @Column
    private Integer rank;

    @ManyToOne
    @MapsId("bookingId")
    @JoinColumn(name = "booking_id")
    @JsonIgnore
    private Booking booking;

    @ManyToOne
    @MapsId("locationId")
    @JoinColumn(name = "location_id")
    @JsonIgnore
    private Location location;

    public BookingRoute() {
    }

    public BookingRoute(Booking booking, Location location, Integer rank) {
        this.pk = new BookingRouteId(booking.getBookingId(), location.getLocationId());
        this.booking = booking;
        this.location = location;
        this.rank = rank;
        booking.getBookingRoutes().add(this);
        location.getBookings().add(this);

    }
....
}

The embeddable id class
@Embeddable
public class BookingRouteId implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(name = "booking_id")
    private Integer bookingId;

    @Column(name = "location_id")
    private Integer locationId;

    public BookingRouteId() {

    }

    public BookingRouteId(Integer bookingId, Integer locationId) {
        super();
        this.bookingId = bookingId;
        this.locationId = locationId;

....
}
here how I send the post method
{
  "pk": {
    "foreignKeyId": "http://localhost:8080/path/to/other/resource/1",
    "foreignKeyId": "http://localhost:8080/path/to/other/resource/2",
    "rank":1
  }

0 个答案:

没有答案