How to implement paging effect in Erlang

1. Front desk

1.1. Use a two-dimensional map to store paging information:

1.1.1. One-dimensional map stores page numbers and paging information, the key is the page number, and the value is the paging information.

1.1.2. The two-dimensional map stores the information of the previous page, the current page and the next page of the paging.

1.1.3. When it is the first page, map[1]["prePage"]="",map[1]["currPage"]="",map[1]["nextPage"]=get the first page Continuation information after one page of data; when it is the second page, map[2]["prePage"]=map[1]["currPage"],map[2]["currPage"]=map[1][ "nextPage"],map[2]["nextPage"]=Continuation information after getting the second page of data.

2. Backstage

2.1. If you get it for the first time:

{Tab,Continue} = ets:match(users,'$1',10),
Tab: Get all the data information of the current page.
Continue: The next page information of the current page.
Send all data information and next page information to the foreground

2.2. If the next time is obtained and the data of the next page is passed from the front desk

% Parse the paging data passed from the front desk
[Tab1,Int1,Int2,Bin,List,Int3] = string:tokens(Continuation,"_"),
% Assemble the paging data passed from the front desk according to the Continue rules
Continue1 = {list_to_atom( Tab1 ),list_to_integer( Int1 ),list_to_integer( Int2 ),<<>>,[], 0 },
 % The custom paging data will be repaired according to this rule
 MS = ets:fun2ms( fun ( OrderRecord = #users{}) -> [ OrderRecord ] end ),
 Continue2 = ets:repair_continuation( Continue1 , MS ),
% Take out the data information of the next page
{Tab2,Continue3} = ets:match(Continue2),
Send all data information and next page information to the foreground

2.3. The acquired data information of the next page:

2.3.1. If it is the last page:

Continue='$end_of_table'.

2.3.2. If not the last page:

Continue={Tab,Int1,Int2,Bin,List,Int3}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326407770&siteId=291194637