UserDAOImpl.java
public List allFindUser(String userID,int currentPage,int lineSize) {
// TODO Auto-generated method stub
List list = new ArrayList();
// sql = "select * from users where userID like '%" + userID
// + "%' order by userID asc";
sql = "select * from users where userID like ? order by ID asc " +
"limit " + ((currentPage-1)*lineSize) + "," + lineSize;
try {
conn = new DBConnection();
prst = conn.getConnectionDB().prepareStatement(sql);
prst.setString(1, "%" + userID + "%");
rs = prst.executeQuery();
while (rs.next()) {
User user = new User();
user.setID(rs.getInt(1));
/* 返红*/
if (!"".equals(userID)) {
String userID2 = rs.getString(2);
userID2 = userID2.replaceAll(userID,
"<font color=\"#ff0000\">" + userID + "</font>");
user.setUserID(userID2);
} else
user.setUserID(rs.getString(2));
user.setUserPassword(rs.getString(3));
user.setName(rs.getString(4));
user.setCompany(rs.getString(5));
user.setDepart(rs.getString(6));
user.setEmail(rs.getString(7));
user.setFields(rs.getString(8));
user.setSystemRole(rs.getString(9));
list.add(user);
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("allUser1持久层数据库出错");
} finally {
try {
rs.close();
prst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("allUser2持久层数据库出错");
}
conn.close();
}
return list;
}
UserAction.java
private List listUser;//数据列表
private String url;// 页面连接路径
private String currentPage;//定义一个当前是第几页
private String pageSize;// 计算出总页数
public String allFindUser() {
// 页面连接路径
// String actionUrl = "allUserList.action";
// 定义如下分页变量
int lineSize = 5;// 1、定义没页要显示的记录数,默认是10条每页
// int currentPage3 = 1;// 2、定义一个当前是第几页
// int pageSize3 = 0;// 计算出总页数
// int allRecorders = 0;// 总记录数 / 每页显示的记录数
String userID;
WorkGroupFacade wg = new WorkGroupFacadeImpl();
HttpServletRequest request = ServletActionContext.getRequest();
userID = request.getParameter("userId");
if (userID == null)
userID = "";
pageSize = request.getParameter("pageSize");
if (pageSize == null)
pageSize = String
.valueOf((userFacede.userCount(userID) + lineSize - 1)
/ lineSize);
currentPage = request.getParameter("cpage");
if (currentPage == null)
currentPage = "1";
url = "allUserList.action";
listUser = new ArrayList();
List listUserTemp;
listUserTemp = userFacede.allFindUser(userID, Integer
.parseInt(currentPage), lineSize);
Iterator it = listUserTemp.iterator();
while (it.hasNext()) {
User user = (User) it.next();
user.setListGroup(wg.selectWorkGroup(user.getFields()));
listUser.add(user);
}
return "success";
}
userList.jsp
<tr>
<td colspan="10" align="right">
<tangs:pages cpage="%{currentPage}" total="%{pageSize}"
url="%{url}" />
第
<s:property value="currentPage" />
页 共
<s:property value="pageSize" />
页
</td>
</tr>