Java Recursive invocation instance

Source: Internet
Author: User

private int num=0;

Private String parentcode = null;

Private String ReturnCode = null;

/**

* Query the top outfield, if the current department's superior department has been outfield, then return to the topmost orgcode, if not the outfield, return to the original Orgcode,

* If there is an outfield in the middle and its parent department is not an outfield, return to the department code of the Outfield. And find all the departments under this department based on ReturnCode.

* SQL mainly uses Where--contact--with to recursively find

* @author 272343 Lili Wu

* @param

* @date 2017-6-12

* @return

*/

@Override

Public String Querycenterorsales (

String Orgcode) {

TODO auto-generated Method Stub

if (num = = 0) {

Divisiondepartmententity parententity = queryparent (Orgcode);

Parentcode = Parententity.getparentorgcode ();

SYSTEM.OUT.PRINTLN ("Initial value, Parentcode" + Parentcode);

Setting the initial ReturnCode

ReturnCode = Orgcode;

SYSTEM.OUT.PRINTLN ("Initial value, Orgcode" + Orgcode);

}

Query up to five times up

if (num<5) {

View the top department information for the current department

Divisiondepartmententity parent=queryparent (Parentcode);

num=num+1;

SYSTEM.OUT.PRINTLN ("Query nth times" + num);

If the upper section is an outfield, transfercenter is the field in the T_bas_org table

if ("Y". Equals (Parent.gettransfercenter ())) {

Get the Parentcode value for the parameter values of the next round of queries

Parentcode=parent.getparentorgcode ();

System.out.println ("Is outfield, parentcode" + Parentcode);

To re-assign a value to Returuncode

Returncode=parent.getcode ();

System.out.println ("Is outfield, returncode" + ReturnCode);

}else{

If not the outfield, to determine whether it is the first query, if not the first time, return to ReturnCode, end the program

if (!returncode.equals (Orgcode) &&num!=1) {

System.out.println ("Not outfield, ReturnCode" + ReturnCode);

return ReturnCode;

}

}

function recursive call, call function itself

Querycenterorsales (Parentcode);

}

If it's always the outfield, at the top, return the field values that are finally assigned

return ReturnCode;

}


Java Recursive invocation instance

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.