1: First talk about recursion
Recursive algorithms: recursive processes are generally implemented through functions or sub-processes. Recursive method: calls its own algorithm directly or indirectly inside a function or sub-procedure.
How to design recursive algorithm
1. Determining the recursive formula
2. Determining the boundary (end) conditions
general pattern of recursionProcedure aaa (K:integer), beginif k=1 then (boundary condition and necessary operation) else Beginaaa (k-1);(repetitive operation); end;end;
2: Application Scenario
Organization table:
organizes a tree structure that contains parent and child nodes in an organization entity. It also contains the user collection, which is the mapping relationship between the user and the organization to establish N:M.
User table:
I'm using the RESTful API to get the tree structure of the Organization, the foreground of the Easyui tree control. Returns the JSON data for the organization, but the program is abnormal, because the organization and organization, organization, and user are nested together, resulting in JSON parsing of the returned results into the dead loop mode.
Three: Recursive solutions
sets the parent node of the organization, the child node collection set to Null, setting only one non-persisted object.
@Transient
Private set<organization> children;
recursive algorithm: resolves Hibernate entity Foreign Key Association, resulting in JSON parsing the dead loop!