-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
QLBF11
authored and
QLBF11
committed
Nov 30, 2020
1 parent
038c487
commit 1c04c0f
Showing
11 changed files
with
268 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cn.itcast.domain; | ||
|
||
/** | ||
* @author QLBF | ||
* @version 1.0 | ||
* @date 2020/11/30 10:49 | ||
*/ | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 分页对象,分页查询要用的,加了泛型T更加通用,其他表也可以用的 | ||
*/ | ||
public class PageBean<T> { | ||
private int totalCount; //总记录数 | ||
private int totalPage; //总页码 | ||
private List<T> list; //每页展示的数据 | ||
private int currentPage; //当前页码 | ||
private int rows; //每页展示的记录数 | ||
|
||
@Override | ||
public String toString() { | ||
return "PageBean{" + | ||
"totalCount=" + totalCount + | ||
", totalPage=" + totalPage + | ||
", list=" + list + | ||
", currentPage=" + currentPage + | ||
", rows=" + rows + | ||
'}'; | ||
} | ||
|
||
public int getTotalCount() { | ||
return totalCount; | ||
} | ||
|
||
public void setTotalCount(int totalCount) { | ||
this.totalCount = totalCount; | ||
} | ||
|
||
public int getTotalPage() { | ||
return totalPage; | ||
} | ||
|
||
public void setTotalPage(int totalPage) { | ||
this.totalPage = totalPage; | ||
} | ||
|
||
public List<T> getList() { | ||
return list; | ||
} | ||
|
||
public void setList(List<T> list) { | ||
this.list = list; | ||
} | ||
|
||
public int getCurrentPage() { | ||
return currentPage; | ||
} | ||
|
||
public void setCurrentPage(int currentPage) { | ||
this.currentPage = currentPage; | ||
} | ||
|
||
public int getRows() { | ||
return rows; | ||
} | ||
|
||
public void setRows(int rows) { | ||
this.rows = rows; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
UserqueryInfo/src/cn/itcast/servlet/FindUserByPageServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cn.itcast.servlet; | ||
|
||
import cn.itcast.domain.PageBean; | ||
import cn.itcast.domain.User; | ||
import cn.itcast.service.UserService; | ||
import cn.itcast.service.impl.UserServiceImpl; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author QLBF | ||
* @version 1.0 | ||
* @date 2020/11/30 12:08 | ||
*/ | ||
@WebServlet("/findUserByPageServlet") | ||
public class FindUserByPageServlet extends HttpServlet { | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
request.setCharacterEncoding("utf-8"); | ||
//1.获取参数,从list.jsp获取的 | ||
String currentPage=request.getParameter("currentPage"); | ||
String rows=request.getParameter("rows"); | ||
|
||
//防止刚进来首页时没值 | ||
if (currentPage==null ||"".equals(currentPage)){ | ||
currentPage="1"; | ||
} | ||
if (rows==null || "".equals(rows)){ | ||
rows="5"; | ||
} | ||
//2.调用service查询 | ||
UserService service=new UserServiceImpl(); | ||
PageBean<User> pb=service.findUserByPage(currentPage,rows); | ||
|
||
//为最后一页点下一页出现异常做准备 | ||
if (Integer.parseInt(currentPage)>=pb.getTotalPage()+1){ | ||
currentPage= String.valueOf(pb.getTotalPage()); | ||
} | ||
|
||
//System.out.println(pb); | ||
//3.将PageBean存入request | ||
request.setAttribute("pb",pb); | ||
|
||
//4.转发到list.jsp | ||
request.getRequestDispatcher("/list.jsp").forward(request,response); | ||
|
||
|
||
|
||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
this.doPost(request, response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters