问题描述
在我的Spring Boot项目中,我有两个实体,例如Seller
和Buyer
。通过扩展CrudRepository
,我使Spring Data REST能够自动为每个CollectionModel
创建一个/sellers
,它们可以通过相应的端点(例如/buyers
和CollectionModel
进行访问)。现在,我想通过编写一个Buyer
来为RepresentationModelProcessor
的{{1}}添加一个自定义的“过滤器”链接:
@Component
public class BuyerCollectionModelProcessor implements
RepresentationModelProcessor<CollectionModel<Buyer>> {
@Override
public CollectionModel<Buyer> process(CollectionModel<Buyer> model) {
// here we add a link to some filter() method from BuyersController class
return model.add(linkTo(methodon(BuyersController.class)
.filterBy(Optional.empty(),Optional.empty()))
.withRel("filter"));
}
}
"_links": {
"self": {
"href": "http://localhost:8080/buyers"
},"filter": {
"href": "http://localhost:8080/buyers/filterBy{?city,age}","templated": true
}
}
问题是,/sellers
现在还具有买方“过滤器”链接:
"_links": {
"self": {
"href": "http://localhost:8080/sellers"
},"templated": true
}
}
如果我决定以类似的方式向/sellers
添加自定义链接,则/sellers
和/buyers
将分别具有两个链接。如何修复该问题并分离自定义链接,以使它们仅包含在CollectionModel
中以用于其相应实体?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)