2017-05-04 47 views
0

我使用Spring Boot开发了示例应用程序。我有一个抽象类(Employee)和两个具体的子类,例如全职和兼职员工。Spring REST存储库显示错误的URL

我更喜欢加入继承类型和JPA提供商创建的3表。

另外我还为Employee创建了REST存储库。看起来象下面这样:

package com.caysever.repository; 

import com.caysever.model.Employee; 
import org.springframework.data.jpa.repository.JpaRepository; 
import org.springframework.data.rest.core.annotation.RepositoryRestResource; 

/** 
* Created by alican on 04.05.2017. 
*/ 
@RepositoryRestResource(path = "employee") 
public interface EmployeeRepository extends JpaRepository<Employee, Long>{ 
} 

当我在调用浏览器的URL **/employee**,我收到如下内容:

{ 
    "fullTimeEmployees" : [ { 
     "name" : "Alican", 
     "surname" : "Akkuş", 
     "birthDay" : "2017-05-04T12:37:20.189+0000", 
     "gender" : "MALE", 
     "totalWorkingHoursOfWeek" : 40, 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/fullTimeEmployee/1" 
     }, 
     "fullTimeEmployee" : { 
      "href" : "http://localhost:8080/fullTimeEmployee/1" 
     } 
     } 
    } 

当我调用这个网址为第一位员工localhost:8080/fullTimeEmployee/1,我得到404状态码,未找到。但我会通过此URL获得第一名员工localhost:8080/employee/1

你可以看到所有的代码在GitHub上 - >https://github.com/AlicanAkkus/jpa-inheritance-strategy

为什么弹簧安置产生fullTimeEmployee网址是什么?

回答

0

我认为,随着@RepositoryRestResource要修改的出口细节,比如使用/ empoyee的,而不是默认值/ fullTimeEmployee

@RepositoryRestResource(collectionResourceRel = "fullTimeEmployees", path = "fullTimeEmployees") 

尝试或者,如果你想使用/员工

@RepositoryRestResource(collectionResourceRel = "employee", path = "employee") 

路径设置要导出此资源的段,并且collectionResourceRel设置值g挖掘链接到收集资源。

希望这会有帮助

+0

嗨丹尼尔,谢谢你的回复。我像你说的那样做了,但没有改变。它仍然生成相同的网址。 –