web 动态分页查询

今天就来分享一下分页查询吧,这种在项目中也比较常见。博主是用easyui 写的,当然还有其他的比如jquery 等 。至于界面,可以参考easyUI文档demo,好了,不说废话,来看代码吧!就贴一些主要的代码吧!
1,先是通过客户端发送请求给control层,也就是你要请求数据的路径,这里就不贴了,刚才也说了,界面可以参考easyui文档;

2,dao

public List<Product_info> fy(@Param("page") int pageindex, @Param("rows") int pagesize); 

由于博主用的框架是ssm;其对应的xmlsql语句为:

 <select id="fy" resultType="com.zking.entity.Product_info" >
            select * from goods_info LIMIT #{page},#{rows}
    </select>

<select id="getcount" resultType="int" >
        select COUNT(*) from goods_info;
    </select>

controll层:

@RequestMapping("goods.xhtml")
    public @ResponseBody Map<String, Object> query(HttpServletRequest req,Product_info pi){
    String  pageindex=req.getParameter("page");
    String  pagesize=req.getParameter("rows");
    //String  pid=req.getParameter("product_id");

     Integer start = (Integer.parseInt(pageindex)-1)*Integer.parseInt(pagesize);
     Integer end = Integer.parseInt(pagesize);
      Map<String, Object> map=new HashMap<String, Object>();
      List<Product_info> pr=new ArrayList<Product_info>();
         Integer count=ud.getcount();
         int total = (int) (count/Integer.parseInt(pagesize));
        if(count%Integer.parseInt(pagesize)!=0){
            total++;
        }
    List<Product_info> pfy=ud.fy(Integer.parseInt(pageindex),Integer.parseInt(pagesize));
          map.put("total", count);
           map.put("rows",pfy);
          System.out.println(map);
        return map;
    }

好了,主要的代码就是这些了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值