刚接触hive,不知道在项目中如何连接hive分页查询一张表的数据,最好有详细代码或小案例,急需!!! 谢谢
2条回答
- grape927 2017-05-27 01:54关注
@RequestMapping(value = "/list") public ModelAndView list(Page page, HttpServletRequest request) throws Exception { ModelAndView mv = this.getModelAndView(); PageData pd = this.getPageData(); // 获取request请求的参数 相当于Map String name = pd.getString("name"); if (StringUtils.isNotBlank(name)) { name = name.trim(); pd.put("name", name); } String num = pd.getString("num"); if (StringUtils.isNotBlank(num)) { num = num.trim(); pd.put("storeNum", num); } page.setPd(pd); // 数据库总的数据总条数 int totalResult = 0; if(page.getTotalResult() < 1) { totalResult = storeService.getTotalCount(pd); } else { totalResult = page.getTotalResult(); } // 当前页 int currentPage = 1; // 每页多少条数据 int showCount = 9; if (pd.getString("page.currentPage") != null) { currentPage = Integer.valueOf(pd.getString("page.currentPage")); currentPage = currentPage < 1 ? 1 : currentPage; } if (pd.getString("page.showCount") != null) { showCount = Integer.valueOf(pd.getString("page.showCount")); } // 总页数 int totalPage;// =(totalRecords+limitPage-1)/limitPage; if (totalResult <= showCount) { totalPage = 1; } else if ((totalResult % showCount) == 0) { totalPage = totalResult / showCount; } else { totalPage = (totalResult / showCount) + 1; } page.setTotalResult(totalResult); page.setCurrentPage(currentPage); page.setTotalPage(totalPage); page.setShowCount(showCount); int start = 1; int end = 0; if (currentPage == 1) { if (totalResult <= showCount) { end = totalResult; } else { end = showCount * currentPage; } } else if (currentPage > 1) { start = showCount * (currentPage - 1); end = showCount * currentPage; } mv.addObject("page", page); mv.addObject("storeList", storeService.getList(pd, start, end)); mv.addObject("pd", pd); // 按钮权限 mv.addObject(Const.SESSION_QX, Auth.getHC()); mv.setViewName("system/list"); return mv; } public String getPageStr(Page page) { int totalResult = page.getTotalResult(); int currentPage = page.getCurrentPage(); int totalPage = page.getTotalPage(); int showCount = page.getShowCount(); boolean entityOrField = true; String pageStr = ""; StringBuffer sb = new StringBuffer(); if(totalResult>0){ sb.append(" <ul>\n"); if(currentPage==1){ sb.append(" <li><a>共<font color=red>"+totalResult+"</font>条</a></li>\n"); sb.append(" <li><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:50px;text-align:center;float:left\" placeholder=\"页码\"/></li>\n"); sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"toTZ();\" class=\"btn btn-mini btn-success\">跳转</a></li>\n"); sb.append(" <li><a>首页</a></li>\n"); sb.append(" <li><a>上页</a></li>\n"); }else{ sb.append(" <li><a>共<font color=red>"+totalResult+"</font>条</a></li>\n"); sb.append(" <li><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:50px;text-align:center;float:left\" placeholder=\"页码\"/></li>\n"); sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"toTZ();\" class=\"btn btn-mini btn-success\">跳转</a></li>\n"); sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(1)\">首页</a></li>\n"); sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+(currentPage-1)+")\">上页</a></li>\n"); } int showTag = 5;//分页标签显示数量 int startTag = 1; if(currentPage>showTag){ startTag = currentPage-1; } int endTag = startTag+showTag-1; for(int i=startTag; i<=totalPage && i<=endTag; i++){ if(currentPage==i) sb.append("<li><a><font color='#808080'>"+i+"</font></a></li>\n"); else sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+i+")\">"+i+"</a></li>\n"); } if(currentPage==totalPage){ sb.append(" <li><a>下页</a></li>\n"); sb.append(" <li><a>尾页</a></li>\n"); }else{ sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+(currentPage+1)+")\">下页</a></li>\n"); sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+totalPage+")\">尾页</a></li>\n"); } sb.append(" <li><a>第"+currentPage+"页</a></li>\n"); sb.append(" <li><a>共"+totalPage+"页</a></li>\n"); sb.append(" <li><select title='显示条数' style=\"width:55px;float:left;\" onchange=\"changeCount(this.value)\">\n"); sb.append(" <option value='"+showCount+"'>"+showCount+"</option>\n"); sb.append(" <option value='20'>20</option>\n"); sb.append(" <option value='30'>30</option>\n"); sb.append(" </select>\n"); sb.append(" </li>\n"); sb.append("</ul>\n"); sb.append("<script type=\"text/javascript\">\n"); //换页函数 sb.append("function nextPage(page){"); sb.append(" top.jzts();"); sb.append(" if(true && document.forms[0]){\n"); sb.append(" var url = document.forms[0].getAttribute(\"action\");\n"); sb.append(" if(url.indexOf('?')>-1){url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" url = url + page + \"&" +(entityOrField?"showCount":"page.showCount")+"="+showCount+"\";\n"); sb.append(" document.forms[0].action = url;\n"); sb.append(" document.forms[0].submit();\n"); sb.append(" }else{\n"); sb.append(" var url = document.location+'';\n"); sb.append(" if(url.indexOf('?')>-1){\n"); sb.append(" if(url.indexOf('currentPage')>-1){\n"); sb.append(" var reg = /currentPage=\\d*/g;\n"); sb.append(" url = url.replace(reg,'currentPage=');\n"); sb.append(" }else{\n"); sb.append(" url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";\n"); sb.append(" }\n"); sb.append(" }else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" url = url + page + \"&" +(entityOrField?"showCount":"page.showCount")+"="+showCount+"\";\n"); sb.append(" document.location = url;\n"); sb.append(" }\n"); sb.append("}\n"); //调整每页显示条数 sb.append("function changeCount(value){"); sb.append(" top.jzts();"); sb.append(" if(true && document.forms[0]){\n"); sb.append(" var url = document.forms[0].getAttribute(\"action\");\n"); sb.append(" if(url.indexOf('?')>-1){url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" url = url + \"1&" +(entityOrField?"showCount":"page.showCount")+"=\"+value;\n"); sb.append(" document.forms[0].action = url;\n"); sb.append(" document.forms[0].submit();\n"); sb.append(" }else{\n"); sb.append(" var url = document.location+'';\n"); sb.append(" if(url.indexOf('?')>-1){\n"); sb.append(" if(url.indexOf('currentPage')>-1){\n"); sb.append(" var reg = /currentPage=\\d*/g;\n"); sb.append(" url = url.replace(reg,'currentPage=');\n"); sb.append(" }else{\n"); sb.append(" url += \"1&"+(entityOrField?"currentPage":"page.currentPage")+"=\";\n"); sb.append(" }\n"); sb.append(" }else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n"); sb.append(" url = url + \"&" +(entityOrField?"showCount":"page.showCount")+"=\"+value;\n"); sb.append(" document.location = url;\n"); sb.append(" }\n"); sb.append("}\n"); //跳转函数 sb.append("function toTZ(){"); sb.append("var toPaggeVlue = document.getElementById(\"toGoPage\").value;"); sb.append("if(toPaggeVlue == ''){document.getElementById(\"toGoPage\").value=1;return;}"); sb.append("if(isNaN(Number(toPaggeVlue))){document.getElementById(\"toGoPage\").value=1;return;}"); sb.append("nextPage(toPaggeVlue);"); sb.append("}\n"); sb.append("</script>\n"); } pageStr = sb.toString(); return pageStr; } public class Page { private int showCount; //每页显示记录数 private int totalPage; //总页数 private int totalResult; //总记录数 private int currentPage; //当前页 private int currentResult; //当前记录起始索引 private boolean entityOrField; //true:需要分页的地方,传入的参数就是Page实体;false:需要分页的地方,传入的参数所代表的实体拥有Page属性 private String pageStr; //最终页面显示的底部翻页导航,详细见:getPageStr(); private PageData pd = new PageData(); private String idArray; //setter/getter 省略 }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 Excel发现不可读取的内容
- ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
- ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
- ¥20 yolov5自定义Prune报错,如何解决?
- ¥15 电磁场的matlab仿真
- ¥15 mars2d在vue3中的引入问题
- ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
- ¥15 算法题:数的划分,用记忆化DFS做WA求调
- ¥15 chatglm-6b应用到django项目中,模型加载失败
- ¥15 CreateBitmapFromWicBitmap内存释放问题。