[英]Spring Data Rest only shows links but no information
I am using Spring data rest with spring boot, so I wrote the code to use endpoints for an entity我正在使用 Spring 数据 rest 和 spring 启动,所以我编写了代码以使用实体的端点
So this is my entity所以这是我的实体
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;
}
And this is where I am using Spring data rest这就是我使用 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>{ }
So when I use the exposed controller for products ( http://127.0.0.1/api/products ) I get the following json因此,当我将暴露的 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
}
}
But theres no information about the products
.但没有关于products
的信息。 Even when I try to get information of the only product I have I got the following json.即使我尝试获取我拥有的唯一产品的信息,我也得到了以下 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"
}
}
}
So you can see, it only shows "_links"
but there's no information.所以你可以看到,它只显示"_links"
但没有任何信息。 How can I fix it?我该如何解决?
I solved my problem by deleting the target file.我通过删除目标文件解决了我的问题。 Then I restarted the application and it worked.然后我重新启动了应用程序并且它工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.