2016-04-11 5 views
4

私はJPAのツリー構造にSpringデータRESTとHATEOASを使用して完全なツリー構造を公開するにはどうすればいいですか?

@Entity 
public class Document { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private int id; 
    private String text; 

    @ManyToOne 
    @JoinColumn(name = "parent") 
    Document parent; 

    @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER) 
    Set<Document> children; 

    (getters and setters) 

} 

と突起を持って

@Projection(name = "all", types = Document.class) 
public interface AllDocumentsProjection { 

    int getId(); 
    String getText(); 
    Set<Document> getChildren(); 

} 

私はURL

ローカルホストでGETリクエストを作るとき:?8080 /文書/ 1投影=すべて

私はルートドキュメントの最初の子のみを取得します。子供の子供ではありません。これは予測可能ですか?それとも別の方法がありますか?

答えて

1

projectionsでリソースを再帰的に埋め込む方法はほとんどありません。私が考えているのはコントローラでこのロジックを手動で処理することだけです:/

-1

Try excerpts

あなたは以下のようなあなたのリポジトリ定義にexcerptProjectionフィールドを追加する必要があります:これは私のために完璧な作品

@RepositoryRestResource(excerptProjection = AllDocumentsProjection.class) 
interface DocumentRepository extends CrudRepository<Document, Integer> {} 
1
@Projection(name = "all", types = Document.class) 
public interface AllDocumentsProjection { 

    int getId(); 
    String getText(); 
    Set<AllDocumentsProjection> getChildren(); 

} 

関連する問題