Java多表查询

.jsp:


    
    	
用户id 用户名 密码 用户权限 用户状态
${user.user_id} ${user.user_name} ${user.password} ${user.user_power} ${user.user_state}

Servlet:
·.usersum():查询user表的总数
·.findAll(PageUtil.pageSize,PageUtil.curPage):查询user表的总页数和当前页数

public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService userService = new UserServiceImpl();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String type = request.getParameter("type");
		if ("finduserAll".equals(type)) {
			finduserAll(request, response);
		} 
	}
	public void finduserAll(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 判断当前页是否等于null,等则赋值为1
		String curPage = request.getParameter("curPage") == null ? "1": request.getParameter("curPage");
		// 给封装的当前页赋值
		PageUtil.curPage = Integer.parseInt(curPage);
		// 赋值总条数
		PageUtil.totalCount = (int) userService.usersum();
		// 赋值总页数= 总条数 + 每页页数
		PageUtil.totalPage = PageUtil.pageTotal(PageUtil.totalCount,PageUtil.pageSize);
		List users = userService.findAll(PageUtil.pageSize,PageUtil.curPage);
		// 返回jsp
		request.setAttribute("users", users);
		// 给公共分页赋值
Page page = new Page(PageUtil.totalPage, PageUtil.totalCount,
				PageUtil.curPage, PageUtil.pageSize);
				request.setAttribute("page", page);
		// 转发到list页面
	request.getRequestDispatcher("/jsp/usermanage/usermanage.jsp").forward(
				request, response);
	}

Web.xml:


  	UserServlet
  	com.fjm.web.UserServlet


   UserServlet
   /servlet/UserServlet

你可能感兴趣的:(JAVA)