复杂分页查询

上次讲过简单的分页查询,就是简单的查询所有信息,不带其他条件,而复杂分页查询就是在简单查询的基础上,加一些条件。我们以搜索为例(搜索完成后带分页效果),这里我们就在上一次的基础上进行修改首先是我们的servlet层:@WebServlet("/searchStudentServlet")public class SearchStudentServlet extends HttpServle...
摘要由CSDN通过智能技术生成

上次讲过简单的分页查询,就是简单的查询所有信息,不带其他条件,而复杂分页查询就是在简单查询的基础上,加一些条件。
我们以搜索为例(搜索完成后带分页效果),这里我们就在上一次的基础上进行修改

首先是我们的servlet层:

@WebServlet("/searchStudentServlet")
public class SearchStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	//创建StudentServiceImpl对象
        StudentService service =  new StudentServiceImpl();
        //beanUtils工具包:将map集合封装成Java对象
        //将前台的数据装入map集合中
        Map<String, String[]> map = new HashMap<String,String[]>(request.getParameterMap());
		//创建一个list集合,用来装查询的信息
        ArrayList<String[]> list = new ArrayList<>();

        int currentPage = 0;
		//判断map中是否包含id/name/age
        if (map.containsKey("id") || map.containsKey("name") || map.containsKey("age")){//如果包含
            list.add(map.get("id"));
            list.add(map.get("name"));
            list.add(map.get("age"));
            request.getSession().setAttribute("mapInfo",list);//将list集合存入session “mapInfo”中
        }else {//如果不包含
       		 //获取session “mapInfo”
            ArrayList<String[]> attribute = (ArrayList<String[]>) request.getSession().getAttribute("mapInfo");
            //如果得到的mapInfo中不为空,将值取出并装入map中
            if (attribute != null){
                map.put("id",attribute.get(0));
                map.put("name",attribute.get(1));
                map.put("age",attribute.get(2));
            }
        }
		
		 //遍历map
        Set<Map.Entry<String, String[]>> entries = map.entrySet();
        Iterator<Map.Entry<String, String[]>> iterator = entries.iterator();
        while (iterator.hasNext())
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值