When inserting a record, set the sort value to the maximum value of the number of child nodes under the parent id plus 1.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.