When inserting a record, let the sort value be the maximum value of the number of child nodes under the parent id plus 1 and seldom write database statements. A very simple statement can be thought of for a long time. In fact, it also means that you are very lazy, I don't want to think about it. I asked my classmates to help me write it, And I recorded it. I will also remind myself of any problems later. It is actually not that difficult, the key is to be willing to try it... Www.2cto.com objective: to insert a record, set the sort value to the maximum value of the number of subnodes under the parent id, and add the Method 1: Write an SQL statement at the DAO layer. @ Query ("select max (obj. orgSort) from Organization obj where obj. orgPid =? 1 ") int getMaxORG_sort (String org_pid); first go to the maximum value. Add the 1 Statement org. setOrgSort (organizationDao. getMaxORG_sort (org. getOrgPid () + 1); in this way, you can add 1 to the maximum value of the child node of the current parent node.