春季 JPA REST 按嵌套属性排序
2022-09-03 02:47:38
我有实体和. 实体有一列:Market
Event
Market
@ManyToOne(fetch = FetchType.EAGER)
private Event event;
接下来我有一个存储库:
public interface MarketRepository extends PagingAndSortingRepository<Market, Long> {
}
和投影:
@Projection(name="expanded", types={Market.class})
public interface ExpandedMarket {
public String getName();
public Event getEvent();
}
使用 REST 查询,我成功获得了具有按市场名称排序的嵌套事件属性的市场列表:/api/markets?projection=expanded&sort=name,asc
{
"_embedded" : {
"markets" : [ {
"name" : "Match Odds",
"event" : {
"id" : 1,
"name" : "Watford vs Crystal Palace"
},
...
}, {
"name" : "Match Odds",
"event" : {
"id" : 2,
"name" : "Arsenal vs West Brom",
},
...
},
...
}
}
但我需要的是获取按事件名称排序的市场列表,我尝试了查询,但它不起作用。我应该怎么做才能使它起作用?/api/markets?projection=expanded&sort=event.name,asc