JSP + MySQL + xpagerv2.0 implement paging!

Source: Internet
Author: User
Tags tld

1. Import the source code or jar package of xpagerv2.0 into the project.

2. Merge page. TLD into your WEB-INF.
3. Add in Web. xml:
<Taglib>
<Taglib-Uri>/xdevelop.net/taglibs/page </taglib-Uri>
<Taglib-location>/WEB-INF/page. TLD </taglib-location>
</Taglib>

4. in JSP:

<% @ Taglib uri = "/xdevelop.net/taglibs/page" prefix = "page" %>
<% @ Page import = "net. xdevelop. util. *" %>

<%

Webapplicationcontext WAC = webapplicationcontextutils
. Getwebapplicationcontext (config. getservletcontext ());
Iuserservice ius = (iuserservice) WAC. getbean ("userservice ");
Int totalrecords = ius. queryqdlistcount (sessinuserid, qsrq, jzrq); // obtain the number of all records meeting the condition

%>
Put <page: pager Total = '<% = totalrecords %>' ultultpagesize = "20"> </Page: pager> on the outer layer of the Data list <Table> </table>.

The core code is as follows:

<! -- Display by page -->
<Page: pager Total = '<% = totalrecords %> 'defaultpagesize = "20">
<Table border = "0" cellspacing = "0" width = "100%">
<Tr>
& Lt; TD width = "75%" colspan = "11" & gt;
<P align = "center"> <B> list of members of the Honglian Construction Bank </B>
</TD>
</Tr>
<TH> id </Th>
<TH> name </Th>
<TH> date </Th>
<TH> check-in time </Th>
<TH> sign-in IP address </Th>
<TH> return time </Th>
<TH> sign back IP address </Th>
<TH> morning overtime hours </Th>
<TH> number of overtime hours in the afternoon </Th>
<TH> total for the current day </Th>
<TH> check-in status </Th>
</Tr>
<% Kqlistvo = NULL;
String fontcolor = "#000000 ";
List useronedaylist = ius. queryqdlist (sessinuserid, qsrq, jzrq,
Index. intvalue (), pagesize. intvalue (); // gets the record set of the specified page
String rowgrcolor = "";
Int rowjo = 0;
For (iterator iter = useronedaylist. iterator (); ITER. hasnext ();){
Kqlistvo = (kqlistvo) ITER. Next ();
If (kqlistvo. getqdtime (). compareto ("") = 0
| Kqlistvo. getqttime (). compareto ("") = 0 ){
Fontcolor = "# ff0000 ";
} Else {
Fontcolor = "#000000 ";
}
If (rowjo % 2 = 0 ){
Rowgrcolor = "# ffffff ";
} Else {
Rowgrcolor = "# e8e8e8 ";
}

%>
<Tr onmouseover = "showmsg ('<% = kqlistvo. getqjmsg (). Trim () %> ');"
Onmouseout = "hidemsg ();" style = "cursor: Hand">
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getxh () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. GetUserName () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getrq () %> (<% = dateutil. getcurrentweekname (sdf_ymd
. Parse (kqlistvo. getrq () %>) </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getqdtime () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getqdip () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getqttime () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getqtip () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getswjbs () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getxwjbs () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. gethjjbs () %> </font> & nbsp; </TD>
<TD bgcolor = "<% = rowgrcolor %>" align = "center"> <font
Color = "<% = fontcolor %>"> <% = kqlistvo. getmsg () %> </font> & nbsp; </TD>
</Tr>
<% Rowjo ++;
} %>
<Tr>
<TD Height = "16" align = "center" colspan = "11"> <page: Navigator
Type = 'text'/> </TD>
</Tr>
</Table>
</Page: pager>

 

5. Java service layer:

// Obtain the number of all records meeting the condition

Public int queryqdlistcount (string userid, string qsrq, string jzrq ){
String SQL = "select count (*) from hlkq where 1 = 1 ";
If (userid! = NULL ){
If (userid. compareto ("gjg ")! = 0 ){
SQL + = "and userid = '" + userid + "'";
}
}
If (qsrq! = NULL & qsrq. Length ()> 0 ){
SQL + = "and RQ> = '" + qsrq + "'";
}
If (jzrq! = NULL & jzrq. Length ()> 0 ){
SQL + = "and RQ <= '" + jzrq + "'";
}
Return (INT) jdbctemplate. queryforlong (SQL );
}

 

// Retrieve only data on the specified page
Public list queryqdlist (string userid, string qsrq, string jzrq, int index,
Int pagesize ){
List qdvolist = NULL;
String SQL = "select username, hlkq. * From hluser, hlkq where hluser. userid = hlkq. userid ";
If (userid! = NULL ){
If (userid. compareto ("gjg ")! = 0 ){
SQL + = "and hluser. userid = '" + userid + "'";
}
}
If (qsrq! = NULL & qsrq. Length ()> 0 ){
SQL + = "and hlkq. RQ> = '" + qsrq + "'";
}
If (jzrq! = NULL & jzrq. Length ()> 0 ){
SQL + = "and hlkq. RQ <= '" + jzrq + "'";
}
SQL + = "order by hlkq. RQ DESC, hlkq. userid ASC limit" + (index-1)
+ "," + Pagesize;
List qdlist = jdbctemplate. queryforlist (SQL );
Map map = NULL;
Kqlistvo kqvo = NULL;
Qdvolist = new arraylist ();
Int I = 1;
For (iterator iter = qdlist. iterator (); ITER. hasnext ();){
Map = (MAP) ITER. Next ();
Kqvo = new kqlistvo ();
Kqvo. setxh (index + (I-1 ));
Kqvo. setuserid (Map. Get ("userid"). tostring (). Trim ());
Kqvo. setusername (Map. Get ("username"). tostring ());
Kqvo. setrq (Map. Get ("RQ"). tostring (). Trim ());

If (Map. Get ("qdtime ")! = NULL ){
// Only take the time, not the date
Kqvo. setqdtime (Map. Get ("qdtime"). tostring (). substring (10 ));
}
If (Map. Get ("qttime ")! = NULL ){
// Only take the time, not the date
Kqvo. setqttime (Map. Get ("qttime"). tostring (). substring (10 ));
}
If (Map. Get ("qdip ")! = NULL ){
Kqvo. setqdip (Map. Get ("qdip"). tostring ());
}
If (Map. Get ("QTip ")! = NULL ){
Kqvo. setqtip (Map. Get ("QTip"). tostring ());
}
If (Map. Get ("swjbs ")! = NULL ){
Kqvo. setswjbs (Map. Get ("swjbs"). tostring ());
}
If (Map. Get ("xwjbs ")! = NULL ){
Kqvo. setxwjbs (Map. Get ("xwjbs"). tostring ());
}
If (Map. Get ("qjmsg ")! = NULL
& Map. Get ("qjmsg"). tostring (). Trim (). Length ()> 0 ){
Kqvo. setqjmsg (Map. Get ("qjmsg"). tostring ());
}
Double dswjbs = double. parsedouble (kqvo. getswjbs ());
Double dxwjbs = double. parsedouble (kqvo. getxwjbs ());

If (dswjbs = 0 & dxwjbs = 0 ){
} Else {
Kqvo. sethjbs (DF. Format (dswjbs + dxwjbs )));
}

If (Map. Get ("qdmsg ")! = NULL ){
Kqvo. setqdmsg (Map. Get ("qdmsg"). tostring (). Trim ());
} Else {
Kqvo. setqdmsg ("not checked ");
}
If (Map. Get ("qtmsg ")! = NULL ){
Kqvo. setqtmsg (Map. Get ("qtmsg"). tostring ());
} Else {
Kqvo. setqtmsg ("unsigned ");
}
Try {
// Weekend
If (dateutil. dayofweek (sdf_ymd.parse (kqvo. getrq () = 7
| Dateutil. dayofweek (sdf_ymd.parse (kqvo. getrq () = 1 ){
Kqvo. setmsg ("overtime on weekends ");
If (kqvo. getqdtime ()! = NULL
& Kqvo. getqdtime (). compareto ("")! = 0
& Kqvo. getqttime ()! = NULL
& Kqvo. getqttime (). compareto ("")! = 0 ){
String SJD = DF. Format (dateutil. getbetweenhours (sdf_hm
. Parse (kqvo. getqdtime (), sdf_hm.parse (kqvo
. Getqttime ())));
// All in the morning
If (dateutil. checkampm (sdf_hm.parse (kqvo. getqdtime () = 0
& Dateutil. checkampm (sdf_hm.parse (kqvo
. Getqttime () = 0 ){
Kqvo. setswjbs (SJD );
Kqvo. setxwjbs ("0 ");
} Else if (dateutil. checkampm (sdf_hm.parse (kqvo
. Getqdtime () = 1
& Dateutil. checkampm (sdf_hm.parse (kqvo
. Getqttime () = 1 ){
Kqvo. setswjbs ("0 ");
Kqvo. setxwjbs (SJD );
} Else {
Double qd = dateutil. getbetweenhours (sdf_hm
. Parse (kqvo. getqdtime (), sdf_hm
. Parse ("12:00 "));
Double Qt = dateutil. getbetweenhours (sdf_hm
. Parse ("12:00"), sdf_hm.parse (kqvo
. Getqttime ()));
Kqvo. setswjbs (DF. Format (Qd ));
Kqvo. setxwjbs (DF. Format (QT ));
}
Kqvo. sethjjbs (SJD );
}
} Else {
Kqvo
. Setmsg (kqvo. getqdmsg (). Trim () + "--"
+ Kqvo. getqtmsg ());
}
} Catch (parseexception E1 ){
E1.printstacktrace ();
}
If (Map. Get ("qjsj ")! = NULL ){
String str_qjsj = map. Get ("qjsj"). tostring (). Trim ();
String str_qjlb = map. Get ("qjlb"). tostring (). Trim ();
String qjsjmsg = "";
String qjlbmsg = "";

If (str_qjsj.compareto ("1") = 0 ){
Qjsjmsg = "Morning ";
} Else if (str_qjsj.compareto ("2") = 0 ){
Qjsjmsg = "PM ";
} Else if (str_qjsj.compareto ("3") = 0 ){
Qjsjmsg = "all day ";
}
If (str_qjlb.compareto ("1") = 0 ){
Qjlbmsg = "Sick leave ";
} Else if (str_qjlb.compareto ("2") = 0 ){
Qjlbmsg = "false ";
} Else if (str_qjlb.compareto ("3") = 0 ){
Qjlbmsg = "other ";
}
If (str_qjsj.compareto ("1") = 0 ){
// Morning
Kqvo. setmsg (qjsjmsg + qjlbmsg + "--" + kqvo. getqtmsg ());
} Else if (str_qjsj.compareto ("2") = 0 ){
// Afternoon
Kqvo. setmsg (kqvo. getqdmsg () + "--" + qjsjmsg + qjlbmsg );
} Else if (str_qjsj.compareto ("3") = 0 ){
// All day
Kqvo. setmsg (qjsjmsg + qjlbmsg );
}
}
Qdvolist. Add (kqvo );
I ++;
}
Return qdvolist;
}

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.