2016-11-21 47 views
3

注:使用Spring 1.4.2引導+ SpringFox 2.6.0春數據休息,SpringFox和JpaRepository定製查找

嗨,我有上過@RepositoryRestResource我的API文檔揚鞭2形式的問題。下面的代碼工作正常(REST訪問OK):

@RepositoryRestResource(collectionResourceRel = "people", path = "people") 
public interface PersonRepository extends JpaRepository<Person, Long> { 
    Person findByLastName(@Param("name") String name); 
} 

而HATEOAS鏈接權太:調用這個URL/API /人/搜索 結束(通知參數 「名稱」):

{ 
    "_links": { 
    "findByLastName": { 
     "href": "http://localhost:8080/api/people/search/findByLastName{?name}", 
     "templated": true 
    }, 
    "self": { 
     "href": "http://localhost:8080/api/people/search" 
    } 
    } 
} 

的REST API是確定的:URL/API /人/搜索/ findByLastName當使用瀏覽器執行

但揚鞭的GET 參數類型被解釋爲「體」,而不是名稱= foobar的返回數據的「查詢」和表單提交(curl ... -d'foobar'...)在404中失敗,試圖提交「名稱」作爲請求主體。 於是,我就設置揚鞭明確,像這樣:

@RepositoryRestResource(collectionResourceRel = "people", path = "people") 
public interface PersonRepository extends JpaRepository<Person, Long> { 
    @ApiOperation("Find somebody by it's last name") 
    @ApiImplicitParams({ 
     @ApiImplicitParam(name = "name", paramType = "query") 
    }) 
    Person findByLastName(@Param("name") @ApiParam(name = "name") String name); 
} 

沒有任何成功,儘管「名稱」很好地保留在形式參數名稱在這個例子:-(

body parameter type on GET query

有誰知道什麼可以做,以使該揚鞭形式工作THX的幫助

回答

1

這是它:?@Param配置春季數據REST,而@RequestParam適合揚鞭

@RepositoryRestResource(collectionResourceRel = "people", path = "people") 
public interface PersonRepository extends JpaRepository<Person, Long> { 

    // @Param Spring Data REST : Use @Param or compile with -parameters on JDK 8 
    // @RequestParam Swagger : paramType=query cf. $Api*Param 

    Person findByLastName(@Param("name") @RequestParam("name") String name); 

} 

我開心!