Spring 数据预测。递归问题

Spring Data Projections. Recursive problems

我对递归投影有疑问。

在 spring 数据休息中使用投影的最佳方式是什么?

我有下一个实体:ProfileParamsChapters.

它们之间的关系如下:

-> 配置文件 ManyToMany 与参数。

-> 参数 ManyToOne 与章节

我已经定义了我的个人预测,并将其与摘录属性一起包含在我的存储库中,但是当我请求它们时,该预测仅在第一级有效,在我的情况下,当我列出配置文件时,我看到我为个人资料实体申请的投影,但没有看到我在第二层为参数实体定义的投影。

投影在这里:

@Projection(name = "profileProjection", types = Profile.class)
public interface ProfileProjection {

    int getId();

    List<Param> getParams();

}

@Projection(name = "paramProjection", types = Param.class)
public interface ParamProjection {

    int getId();

    Chapter getChapter();

    List<Profile> getProfiles();

}

另外,当我只想看到第一层时,我看到配置文件递归地关联到我的参数。停止递归的最佳方法是什么?我试过像这样在 url 中使用 投影参数 ,但效果不佳。

....../parametros?projection=parametroProjection

是否可以在 url 中应用两个投影?

我不太确定你在问什么。如果你想结合投影,你可以这样做:

@Projection(name = "profileProjection", types = Profile.class)
public interface ProfileProjection {
    int getId();

    // note type of list is ParamProjection 
    List<ParamProjection> getParams(); 
}

@Projection(name = "paramProjection", types = Param.class)
public interface ParamProjection {

    int getId();
    Chapter getChapter();
}

....../parametros?projection=profileProjection