课程-day19练习-jdbc条件查询分页_第1页
课程-day19练习-jdbc条件查询分页_第2页
课程-day19练习-jdbc条件查询分页_第3页
课程-day19练习-jdbc条件查询分页_第4页
已阅读5页,还剩5页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

//获取表单id,提交表 ementById("表单}publicpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)ServletException,IOException//获取客户端复选框的值,返回字符串数String[]pids=request.getParameterValues("checkItem");ProductServiceservice=newProductService(); }publicpublicvoidpids){ProductDaodao=newProductDao();try{if(pids!=nullpids.length>0){for(Stringpid:}}}catch(SQLExceptione)}第2章案例:分页查相关知识:sql格式:格式:select*fromlimit参数2:每页显示个数pageSizeselect*fromproductslimit0,5;#5条。select*fromproductslimit5,5;#5条。select*fromproductslimit10,55条。select*fromproductslimit?,5;#pageNumber5startIndex=(pageNumber-1)*publicpublicclassPageBean ongtotalPage;//总页数privateintpageNum;//当前页privateintpageSize;//每页条数 ongtotalCount;//总条 ist<T>list显示的商品数据publiclonggetTotalPage(){return}publicvoidsetTotalPage(long{this.totalPage=}publicint{return}publicvoidsetPageNum(int{this.pageNum=}publicint{return}publicvoidsetPageSize(int{this.pageSize=}publicpubliclong{return}publicvoidsetTotalCount(long{this.totalCount=}publicList<T>{return}publicvoidsetList(List<T>{this.list=}}publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding("UTF-//获取页面提交的方法调Stringmethod=request.getParameter("method");if("list".equals(method)){//不带分页查询数list(request,}elseif("pageList".equals(method))//带分页查询数pageList(request,}}throwsServletException,IOException{//获取当前页StringpageNumStr=if(pageNumStr==null||"".equals(pageNumStr)){}intpageNum=Integer.parseInt(pageNumStr);ProductServiceservice=newProductService();//调用业务层方法,每页显12条,获取PageBeanPageBean<Product>pageBean=request.setAttribute("pageBean",pageBean);request.setAttribute("pageBean",pageBean);}privatevoidlist(HttpServletRequestrequest,HttpServletResponseresponse)}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doGet(request,}publicpublicPageBean<Product>findByPage(intpageNum,int******ongtotalPage;//总页privateintpageNum;//privateintpageSize;//每页条ongtotalCount;//总条业务层封装对象PageBean,返回视图PageBean<Product>pageBean=ne ProductDaodao=newProductDao();longtotalCount=dao.getTotalCount();inttotalPage=(int)Math.ceil(1.0*totalCount/pageSize);//sql="select*fromproductlimit(当前页-1*每页显示条数),pageSize"List<Product>listdao.findByPage((pageNum-1)*pageSize,pageSize);ex){;}return}publicpublicList<Product>findByPage(inti,intpageSize)throws{QueryRunnerrunner=newQueryRunner(DataSourceUtils.getDataSource());Stringsql="select*fromproductlimit?,?"; }publiclonggetTotalCount()throwsQueryRunnerrunner=newQueryRunner(DataSourceUtils.getDataSource());Stringsql="selectcount(*)fromproduct";return(long)runner.query(sql,new} <!--如果已经是第一页,不能点击<c:iftest="${pageBean.pageNum==1<li<ahref="javascript:void(0);"aria-<spanaria-<c:iftest="${pageBean.pageNum!=1<liontextPathan.pageNum-1}"aria-<spanaria-<!-循环显示页循环1开始,到从页数结--<c:forEachbegin="1"end="${pageBean.totalPage}"<!--如果是当前页,背景色设置蓝色<c:if<c:iftest="${pageBean.pageNum==i ontextPath}/pageProduct?method=pageList&pageNum=${pageSc${pageScope.i<c:iftest="${pageBean.pageNum!=iontextPath${pageScope.i<!--判断如果最后一页,下一页不能点击<li<ahref="javascript:void(0);"aria-<spanaria-<c:iftest="${pageBean.pageNum!=pageBean.totalPage<li ontextPath}/pageProduct?method=pageList&pageNum=${pageBe<spanaria-第3章案例:条件查商商品名称<inputtype="text" ; name="minPrice">--是否热门<optionvalue="-1">不限<optionvalue="1">是<optionvalue="0">否 <button<buttontype="button"id="del"name="del"value="删除class="button_add"onclick="findProduct()"查询publicpublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)ServletException,ServletException,IOExceptionrequest.setCharacterEncoding("UTF-//Map<String,String[]>parameterMap=request.getParameterMap();Findfind=newFind();tryBeanUtils.populate(find,}catch(IllegalAccessException| Exception{}ProductServiceservice=newProductService();List<Product>productList=service.findProduct(find);request.setAttribute("productList",productList);}publicList<Product>findProduct(Findfind){List<Product>list=null;ProductDaopublicList<Product>findProduct(Findfind){List<Product>list=null;ProductDaodao=newProductDao();try{list=}catch(SQLExceptione)}return}publicpublicList<Product>findProduct(Findfind)throwsQueryRunnerrunner=new////sqlStringsql="select*fromproductwhere//定义集合 查询条List<Object>list=new//判断查询的条件,拼接sql&&!find.getPname().eq

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论