web动态分页查询

    xiaoxiao2021-03-25  90

    今天就来分享一下分页查询吧,这种在项目中也比较常见。博主是用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; }

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

    转载请注明原文地址: https://ju.6miu.com/read-36176.html

    最新回复(0)