[英]Spring Data Rest only shows links but no information
我正在使用 Spring 數據 rest 和 spring 啟動,所以我編寫了代碼以使用實體的端點
所以這是我的實體
package com.angelol.ecommerce.entities;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import lombok.Data;
@Entity
@Table(name="f_product")
@Data
public class Product{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "sku")
private String sku;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "funit_price")
private BigDecimal unitPrice;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "active")
private boolean active;
@Column(name = "date_created")
@CreationTimestamp
private Date dateCreated;
@Column(name = "last_update")
@UpdateTimestamp
private Date lastUpdate;
@ManyToOne
@JoinColumn(name = "category_id", nullable = false)
private ProductCategory category;
}
這就是我使用 Spring 數據 rest 的地方
package com.angelol.ecommerce.dao;
import com.angelol.ecommerce.entities.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;
@CrossOrigin
@RepositoryRestResource(collectionResourceRel = "product", path = "products")
public interface ProductRepository extends JpaRepository<Product, Long>{ }
因此,當我將暴露的 controller 用於產品( http://127.0.0.1/api/products )時,我得到以下 json
{
"_embedded" : {
"product" : [ {
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/api/products/3"
},
"product" : {
"href" : "http://127.0.0.1:8080/api/products/3"
},
"category" : {
"href" : "http://127.0.0.1:8080/api/products/3/category"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/api/products/"
},
"profile" : {
"href" : "http://127.0.0.1:8080/api/profile/products"
}
},
"page" : {
"size" : 20,
"totalElements" : 1,
"totalPages" : 1,
"number" : 0
}
}
但沒有關於products
的信息。 即使我嘗試獲取我擁有的唯一產品的信息,我也得到了以下 json。
{
"_links" : {
"self" : {
"href" : "http://127.0.0.1:8080/api/products/3"
},
"product" : {
"href" : "http://127.0.0.1:8080/api/products/3"
},
"category" : {
"href" : "http://127.0.0.1:8080/api/products/3/category"
}
}
}
所以你可以看到,它只顯示"_links"
但沒有任何信息。 我該如何解決?
我通過刪除目標文件解決了我的問題。 然后我重新啟動了應用程序並且它工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.