JSP:

<html>
  <head>
    <title>My JSP 'inOutKuPage.jsp' starting page</title>
 <style type="text/css">
        table{
          border-color: blue;
        }
        .a{
         background-color: blue;
         text-align: center;
        }
    </style>
 <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.10.2.js"></script>
 <script type="text/javascript">
       $(function(){
        $("#query").click(function(){
           var url='<%=request.getContextPath()%>/inOutPage.do';
           $.post(url,
               {
                  inoutno:$("#no").val(),
                  people:$("#people").val()
               },
               function(data){
                 $("tr[id^='order']").remove();
                 $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
                 $.each(data.records,function(i,d){
                    var rows="<tr id='order'"+i+">";
                    rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
                 });
               },
               "json");
        });
        $("#pre").click(function(){
           var url='<%=request.getContextPath()%>/inOutPage.do';
           $.post(url,
                {
                 inoutno:$("#no").val(),
                 people:$("#people").val(),
                 pageNo:$("#prePage").val(),
                },
                function(data){
                $("tr[id^='order']").remove();
     $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
     $.each(data.records,function(i,d){
      var rows="<tr id='order'"+i+">";
        rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
     });
                },
           "json");
        });
        $("#next").click(function(){
              var url='<%=request.getContextPath()%>/inOutPage.do';
               $.post(url,
                {
                 inoutno:$("#no").val(),
                 people:$("#people").val(),
                 pageNo:$("#nextPage").val(),
                },
                  function(data){
                $("tr[id^='order']").remove();
     $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
     $.each(data.records,function(i,d){
      var rows="<tr id='order'"+i+">";
        rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
     });
                },
                "json");
        });
      });
 </script>
  </head>
 
  <body>
        <table border="1px">
        <tr>
           <input type="hidden" id="prePage">
     <input type="hidden" id="nextPage">
           <td class="a">入出库单编号</td>
           <td><input type="text" name="no" id="no"></td>
           <td class="a">入/出库</td>
           <td><input type="radio" name="a" value="入库" id="a">入库
               <input type="radio" name="a" value="出库" id="a">出库
           </td>
        </tr>
        <tr>
           <td class="a">经办人</td>
           <td><input type="text" name="people" id="people"></td>
           <td class="a">日期</td>
           <td><input type="text" name="date" id="date"></td>
        </tr>
        <tr>
           <td colspan="4" align="center"><input type="button" value="查询" id="query">
           <input type="submit" value="清空">
           <input type="button" id="pre" value="上一页">
     <input type="button" id="next" value="下一页">
     <span id="total"></span></td>
        </tr>
     </table>
     <table border="1px" id="show">
         <tr>
           <td>入出库单编号</td>
           <td>客户名称</td>
           <td>经办人</td>
           <td>入/出库</td>
           <td>操作时间</td>
           <td>操作</td>
         </tr>
                  </table>
  </body>
</html>

DAO:

public class InOutPageDao extends BaseDao {
 public List<InOut> findCusinfosByPageNo(InOut condition,PageUtitily<InOut> page) {
  List<InOut> list =new ArrayList<InOut>();
  String select="select * from inout where 1=1";
  StringBuilder sb = new StringBuilder(select);
  List<Object> params = new ArrayList<Object>();
  if(condition!=null){
   if(condition.getInoutno()!=null&& !"".equals(condition.getInoutno())){
   sb.append(" AND INOUTNO LIKE ?");
   params.add("%"+condition.getInoutno()+"%");
  }
      if(condition.getPeople()!=null &&!"".equals(condition.getPeople())){
       sb.append(" AND PEOPLE LIKE ?");
       params.add("%"+condition.getPeople()+"%");
  }
  }
  params.add(page.getStartRecord());
  params.add(page.getEndRecord());
  ResultSet rs = this.executeQueryForPage(sb.toString(), params);
  try {
   while(rs.next()){
     InOut cus=new InOut();
     cus.setInoutno(rs.getString("INOUTNO"));
     cus.setUsername(rs.getString("USERNAME"));
     cus.setPeople(rs.getString("PEOPLE"));
     cus.setInout(rs.getString("INOUT"));
     cus.setCtime(rs.getString("CTIME"));
    list.add(cus);
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }finally{
   this.closeAll();
  }
  return list;
 }
 public int findCusinfosCount(InOut condition) {
  String select ="SELECT * FROM INOUT C where 1=1";
  StringBuilder sb = new StringBuilder(select);
  List<Object> params = new ArrayList<Object>();
  if(condition!=null){
   if(condition.getInoutno()!=null&& !"".equals(condition.getInoutno())){
   sb.append(" AND INOUTNO LIKE ?");
   params.add("%"+condition.getInoutno()+"%");
  }
      if(condition.getPeople()!=null &&!"".equals(condition.getPeople())){
       sb.append(" AND PEOPLE LIKE ?");
       params.add("%"+condition.getPeople()+"%");
  }
  }
  return this.executeQueryForTatalCount(sb.toString(), params);
  
 }
}

实体类:

public class PageUtitily<T> {
  private List<T> records;
  private int curPage=1;//当前页码
  private int totalRecords;//符合条件的总记录数
  private int totalPages;//总页码数
  private int pageSize=3;//页面大小
  private int nextPage;//下一页
  private int prePage;//上一页
 
  private int startRecord;
  private int endRecord;
 
  public List<T> getRecords() {
  return records;
 }

public void setRecords(List<T> records) {
  this.records = records;
 }

public int getPageSize() {
  return pageSize;
 }

public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }

public int getCurPage() {
  return curPage;
 }

public int getNextPage() {
  return nextPage;
 }

public int getPrePage() {
  return prePage;
 }

public int getStartRecord() {
  return startRecord;
 }

public int getEndRecord() {
  return endRecord;
 }
 
 public PageUtitily(int pageNo){
  this.curPage=pageNo;
  this.startRecord=(this.curPage-1)*pageSize+1;
  this.endRecord=this.curPage*pageSize;
  this.prePage=this.curPage-1;
  if(this.prePage<=0){
   this.prePage=1;
  }
 }
 
 public void setTotalRecords(int totalRecords) {
  this.totalRecords = totalRecords;
  //计算总页码
  this.totalPages=this.totalRecords%pageSize==0?this.totalRecords/this.pageSize:this.totalRecords/this.pageSize+1;
  
  //计算下一页
  this.nextPage=this.curPage+1;
  if(this.nextPage>totalPages){
   this.nextPage=totalPages;
  }
 }
}

SERVICE:

public class InOutPageService {
 InOutPageDao iod=new InOutPageDao();
 public PageUtitily<InOut> findCusOrderByPage(InOut condition,int pageNo) {
  PageUtitily<InOut> pageObj = new PageUtitily<InOut>(pageNo);
  pageObj.setTotalRecords(iod.findCusinfosCount(condition));
  
  List<InOut> list = iod.findCusinfosByPageNo(condition, pageObj);
  pageObj.setRecords(list);
  return pageObj;
 }

}

SERVLET:

public class InOutPageServlet extends HttpServlet {
    InOutPageService iops=new InOutPageService();
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  doPost(req, resp);
 }

@Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  req.setCharacterEncoding("utf-8");
   String inoutno=req.getParameter("inoutno");
    String inout=req.getParameter("a");
    String people=req.getParameter("people");
    String ctime=req.getParameter("date");
   
          String curPage=req.getParameter("pageNo");
          if(curPage==null||"".equals(curPage)){
           curPage="1";
          }
    InOut io=new InOut(inoutno, people, inout, ctime);
    PageUtitily<InOut> page=iops.findCusOrderByPage(io, Integer.valueOf(curPage));
    JSONObject array=JSONObject.fromObject(page);
    resp.setContentType("text/html;charset=utf-8");
    PrintWriter out=resp.getWriter();
    out.print(array.toString());
    out.close();
 }
}

POS管理系统之出入库单分页查询的更多相关文章

  1. .net通用CMS快速开发框架——问题1:Dapper通用的多表联合分页查询怎么破?

    最近在弄一个东东,类似那种CMS的后台管理系统,方便作为其它项目的初始化框架用的. 现在遇到个问题,如标题所示:Dapper通用的多表联合分页查询怎么破? 难道只能通过拼接sql或者使用存储过程吗?我 ...

  2. 阿里云对象存储服务,OSS使用经验总结,图片存储,分页查询

    阿里云OSS-使用经验总结,存储,账号-权限,分页,缩略图,账号切换 最近项目中,需要使用云存储,最后选择了阿里云-对象存储服务OSS.总的来说,比较简单,但是仍然遇到了几个问题,需要总结下. 1.O ...

  3. 小书MybatisPlus第4篇-表格分页与下拉分页查询

    本文为mybatis系列文档的第4篇,前三篇请访问下面的网址. 小书MybatisPlus第1篇-整合SpringBoot快速开始增删改查 小书MybatisPlus第2篇-条件构造器的应用及总结 小 ...

  4. JdbcTemplate+PageImpl实现多表分页查询

    一.基础实体 @MappedSuperclass public abstract class AbsIdEntity implements Serializable { private static ...

  5. 用Hibernate和Struts2+jsp实现分页查询、修改删除

    1.首先用get的方法传递一个页数过去 2.通过Struts2跳转到Action 3.通过request接受主页面index传过的页数,此时页数是1, 然后调用service层的方法获取DAO层分页查 ...

  6. MySQL、Oracle和SQL Server的分页查询语句

    假设当前是第PageNo页,每页有PageSize条记录,现在分别用Mysql.Oracle和SQL Server分页查询student表. 1.Mysql的分页查询: SELECT * FROM s ...

  7. 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...

  8. mysql 分页查询

    mysql,; : mysql,; -last. //如果只给定一个参数,它表示返回最大的记录行数目: mysql; 个记录行 ,n. 动态传参的分页查询 SELECT * FROM table LI ...

  9. MongoDB 分页查询的方法及性能

    最近有点忙,本来有好多东西可以总结,Redis系列其实还应该有四.五.六...不过<Redis in Action>还没读完,等读完再来总结,不然太水,对不起读者. 自从上次Redis之后 ...

随机推荐

  1. C#中ref,out

    out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out 关键字 比如 ...

  2. jsp页面动态显示时间

    <SCRIPT language="JavaScript">  function disptime(){ var time = new Date(); var hour ...

  3. 2016.12.01 搭建dendroid备忘

    在2014年的时候看了freebuf的那篇,感觉很6,2014年搭了就一遍成功了,事过两年,物是人非啊,2016搞了云,没事测试,搞了一遍死活不成功,第二天测试成功,过程逗比坎坷,没什么难的 //环境 ...

  4. 转:android异步任务设计思详解(AsyncTask)

    这里说有设计思想是我根据查看Android源代码提炼出来的代码逻辑,所以不会跟Google工程师的原始设计思想100%符合(也有可能是0%),但是本文一定可以帮助你理解AsyncTask,也可能有一些 ...

  5. etl学习系列1——etl工具安装

    ETL(Extract-Transform-Load的缩写,即数据抽取.转换.装载的过程),对于企业或行业应用来说,我们经常会遇到各种数据的处理,转换,迁移,所以了解并掌握一种etl工具的使用,必不可 ...

  6. Ajax在html页面获取后台XML文件资源

    一.准备工具 站长吧ASP调试工具.exe,这个工具是为了快速建立asp环境,方便调试. 二.建立文件夹 1.建立网站根文件夹,名字随意,将站长吧ASP调试工具.exe复制到根文件夹: 2.建立xml ...

  7. Java Concurrent之 AbstractQueuedSynchronizer

    ReentrantLock/CountDownLatch/Semaphore/FutureTask/ThreadPoolExecutor的源码中都会包含一个静态的内部类Sync,它继承了Abstrac ...

  8. 闪回恢复区大小不够。报ORA-19809、ORA-19804

    问题: 闪回恢复区大小不够,rman默认备份路径报错.RMAN> backup database;Starting backup at 01-DEC-14using target databas ...

  9. mongo安全:增加用户名密码

    0.简述:在非auth下创建账户,然后重启 1.以不需要用户名密码的方式启动mongodb 2.运行客户端mongo,输入以下指令 show dbs;use admin;db.createRole({ ...

  10. xmind8

    win10企业版安装 xmind.zip,打开应用程序报下面的错 解决办法是 先备份xmind8下的XMind.ini文件 Open up Xmind.ini and replace "Ap ...