A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package cn.itcast.web.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;
import java.util.Map;

@WebServlet("/findUserByPageServlet")
public class FindUserByPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置提交过来的参数编码
        request.setCharacterEncoding("utf-8");

        //获取提交的当前的页码与每页总记录数的参数
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");

        //判断currentPage与rows
        if(currentPage==null||"".equals(currentPage)){
            currentPage="1";
        }
        if(rows==null||"".equals(rows)){
            rows="10";
        }

        //获取前端页面提交的关于条件查询的参数
        Map<String, String[]> condition = request.getParameterMap();
        //将condition存入request对象
        request.setAttribute("condition",condition);
        //调用service方法获取查询得到的pageBean对象
        UserService userService = new UserServiceImpl();
        PageBean<User> pb = userService.findUsersByPage(currentPage, rows,condition);
        //System.out.println(pb);
        //将pb对象存入request域中
        request.setAttribute("pb", pb);
        //转发到list.jsp页面
        request.getRequestDispatcher("/list.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

1 个回复

倒序浏览
你个骚包
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马