- MySQL Paging
- Parameters to be required:
- PageSize How many data are displayed per page
- PageNumber pages coming from the client
- Total number of records in the Totalrecouds table select COUNT (*) from table name
- TotalPages Total Pages
- totalpages=totalrecouds%pagesize==0?totalrecouds/pagesize:totalrecouds/pagesize+1
- Pages Start location
- pages= pagesize* (pagenumber-1)
- SQL statements:
- SELECT * from table name limit pages, pageSize;
- MySQL paging relies on the keyword limit it requires two parameters: start position and pagesize
- Start Position = page Size * (pages-1)
- Starting position =pagesize* (PageNumber-1)
One: Paging needs:
The client passes the start (page number), limit (number of bars per page) two parameters to page through the data in the database table, then we know that the MySQL database provides paging function limit m,n, but the use of this function is different from our needs, So we need to adapt to the actual situation to rewrite the appropriate page for our own statement, the specific analysis is as follows:
Like what:
The SQL for querying data 1th through 10th is: SELECT * FROM table limit 0, 10; We need to query the first page of data: SELECT * FROM table limit (1-1) *10,10;
The SQL for querying data 10th through 20th is: SELECT * FROM table limit 10, 20; We need to query the second page of data: SELECT * FROM table limit (2-1) *10,10;
The SQL for querying data 20th through 30th is: SELECT * FROM table limit 20, 30; We need to query the third page of data: SELECT * FROM table limit (3-1) *10,10;
Second: Through the above analysis, we can get to meet our own needs of the paging SQL format is: SELECT * FROM table limit (start-1) *limit,limit; Where start is the page number, limit is the number of bars displayed per page.
-
- Oracle Paging
- PageSize How many data are displayed per page
- PageNumber pages coming from the client
- Total number of records in the Totalrecouds table select COUNT (*) from table name
- TotalPages Total Pages
- totalpages=totalrecouds%pagesize==0?totalrecouds/pagesize:totalrecouds/pagesize+1
- StartPage Start position
- Startpage= pagesize* (pagenumber-1) +1
- Endpage=startpage+pagesize
- SQL statements
- Select A.* from
- (
- Select RowNum num, t.* from table name t where column = some value order by ID ASC
- ) A
- where A.num>=startpage and A.num<endpage
Select t2.* from (
Select T1.*,rownum rn from (
Select Employee_id,emp_name,email,phone_number,hire_date,j.job_title,
Salary,d.department_name from Employeess E
Left join JOBSS J on e.job_id=j.job_id
Left join DEPARTMENTSS D on e.department_id=d.department_id
) T1 where rownum <= #{up}
) T2 where RN > #{down}
Mapper:list<employees> Findbypageno (@Param ("Up") int up, @Param (' down ') int down);
- Dao:
Public list<employees> Findbypageno (int pageno, int pagenum) {
int up=pageno*pagenum;
int down= (pageNo-1) *pagenum;
Return Employeemapper.findbypageno (Up,down);
}
- Service:
Public list<employees> Findbypageno (int pageno, int pagenum) {
Return Employeedao.findbypageno (pageno,pagenum);
}
- Controller
@RequestMapping ("Employeelist.do")
Public String list (int pageno, model model) {
Quantity per page
int pagenum = 3;
Total quantity
int count = Employeeservice.findmaxsize ();
Total pages
int Pagemax = count% Pagenum = = 0? Count/pagenum:count/pagenum + 1;
System.out.println ("list---------");
Page judgment
if (PageNo < 1) {
PageNo = 1;
}
if (PageNo > Pagemax) {
PageNo = Pagemax;
}
list<employees> all = Employeeservice.findbypageno (PageNo, pagenum);
Return the results to the page display
Model.addattribute ("EmployeeList", all);
Model.addattribute ("PageNo", PageNo);
Model.addattribute ("Pagemax", Pagemax);
return "EmployeeList";
}
MySQL, Oracle Paging query