Home > Back-end >  On Java functional programming
On Java functional programming

Time:03-01

Using Java read secondary database, returns an org. Secondary. Driver. The Result type, need to be converted into List And found that there were & lt; T> List The list (Function Var1), the functional programming, should how to call, please?

 
Public Result selectChild (Long departmentId) {

Try {
Map ParamentMap=Collections. SingletonMap (" departmentId ", departmentId);

String sqlText="MATCH (N: WechatDepartment) - [child] - & gt; (M: WechatDepartment) \ n + "
"WHERE N.d epartmentId={departmentId} \ n" +
"RETURN ID (M) as ID, m. epartmentId as departmentId, M.n ame as the name, M.o rder as order, M.e nable as enable";

//returns an org. Secondary. Driver. The Result type
Result the Result=session. The run (sqlText paramentMap);

//needs into List

//1 List< method; Record> The list ();
List Records.=the result list ();

//method 2 & lt; T> List The list (Function Var1)
?????


return result;
} the catch (Exception e) {
System.out.println(e);
Throw e;
} the finally {
//the session. The close ();
}
}


 
Public interface Result extends Iterator {
List Keys ();

Boolean hasNext ();

Record next ();

Record in use () throws NoSuchRecordException;

Record the peek ();

Stream The stream ();

List The list ();

List The list (Function Var1);

ResultSummary consume ();
}


CodePudding user response:

You can define a Function object, and then passed to the method of list

Function GetWechatDepartmenList=record - & gt; {
The return from pumped WechatDepartment logical record;
//such as WechatDepartment department=new WechatDepartment ();
Department. Elegantly-named setName (record. GetName)
Department. SetCode (record. GetDeptCode);
Return department;
}

List The departments.=the result list (getWechatDepartment);
  • Related