1.将XPAGERv2.0的源码或jar包导入项目。
2.将page.tld拷入您的WEB-INF下。
3.在web.xml添加:
4.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);//取得满足条件的所有记录数
%>
把
核心代码如下:
虹联建行组成员签到清单 %>
ID
姓名
日期
签到时间
签到IP
签退时间
签退IP
上午加班小时数
下午加班小时数
当天合计
签到情况
<%KqListVO kqListVO = null;
String fontColor = "#000000";
List userOneDayList = ius.queryQdList(sessinUserID, qsrq, jzrq,
index.intValue(), pageSize.intValue());//取得指定页的记录集
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";
}
onMouseOut="hideMsg();" style="cursor:hand">
color="<%=fontColor%>"><%=kqListVO.getXh()%>
color="<%=fontColor%>"><%=kqListVO.getUsername()%>
color="<%=fontColor%>"><%=kqListVO.getRq()%>(<%=DateUtil.getCurrentWeekName(sdf_ymd
.parse(kqListVO.getRq()))%>)
color="<%=fontColor%>"><%=kqListVO.getQdtime()%>
color="<%=fontColor%>"><%=kqListVO.getQdip()%>
color="<%=fontColor%>"><%=kqListVO.getQttime()%>
color="<%=fontColor%>"><%=kqListVO.getQtip()%>
color="<%=fontColor%>"><%=kqListVO.getSwjbs()%>
color="<%=fontColor%>"><%=kqListVO.getXwjbs()%>
color="<%=fontColor%>"><%=kqListVO.getHjjbs()%>
color="<%=fontColor%>"><%=kqListVO.getMsg()%>
<%rowjo++;
}%>
5.java service层:
//取得满足条件的所有记录数
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);
}
//只取得指定页的数据
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) {
// 只取时间,不要日期
kqVO.setQdtime(map.get("qdtime").toString().substring(10));
}
if (map.get("qttime") != null) {
// 只取时间,不要日期
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.setHjjbs((df.format(dswjbs + dxwjbs)));
}
if (map.get("qdmsg") != null) {
kqVO.setQdmsg(map.get("qdmsg").toString().trim());
} else {
kqVO.setQdmsg("未签到");
}
if (map.get("qtmsg") != null) {
kqVO.setQtmsg(map.get("qtmsg").toString());
} else {
kqVO.setQtmsg("未签退");
}
try {
// 是周末
if (DateUtil.dayOfWeek(sdf_ymd.parse(kqVO.getRq())) == 7
|| DateUtil.dayOfWeek(sdf_ymd.parse(kqVO.getRq())) == 1) {
kqVO.setMsg("周末加班");
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())));
// 都在上午
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 = "上午";
} else if (str_qjsj.compareTo("2") == 0) {
qjsjmsg = "下午";
} else if (str_qjsj.compareTo("3") == 0) {
qjsjmsg = "整天";
}
if (str_qjlb.compareTo("1") == 0) {
qjlbmsg = "病假";
} else if (str_qjlb.compareTo("2") == 0) {
qjlbmsg = "事假";
} else if (str_qjlb.compareTo("3") == 0) {
qjlbmsg = "其它";
}
if (str_qjsj.compareTo("1") == 0) {
// 上午
kqVO.setMsg(qjsjmsg + qjlbmsg + "--" + kqVO.getQtmsg());
} else if (str_qjsj.compareTo("2") == 0) {
// 下午
kqVO.setMsg(kqVO.getQdmsg() + "--" + qjsjmsg + qjlbmsg);
} else if (str_qjsj.compareTo("3") == 0) {
// 整天
kqVO.setMsg(qjsjmsg + qjlbmsg);
}
}
qdVOList.add(kqVO);
i++;
}
return qdVOList;
}