设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mybatis超详细插件机制解析,弄懂拦截器So easy(9)

发布时间:2019-12-25 22:25 所属栏目:115 来源:站长网
导读:inttotalPage=totalCount/page.getPageSize()+((totalCount%page.getPageSize()==0)?0:1); page.setPages(totalPage); }catch(SQLExceptione){ log.error(Ignorethisexception,e); }finally{ try{ rs.close(); }cat

      int totalPage = totalCount / page.getPageSize() + ((totalCount % page.getPageSize() == 0) ? 0 : 1); 

      page.setPages(totalPage); 

    } catch (SQLException e) { 

      log.error("Ignore this exception", e); 

    } finally { 

      try { 

        rs.close(); 

      } catch (SQLException e) { 

        log.error("Ignore this exception", e); 

      } 

      try { 

        countStmt.close(); 

      } catch (SQLException e) { 

        log.error("Ignore this exception", e); 

      } 

    } 

  } 

 

  /** 

   * 代入参数值 

   * 

   * @param ps 

   * @param mappedStatement 

   * @param boundSql 

   * @param parameterObject 

   * @throws SQLException 

   */ 

  private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql, 

                Object parameterObject) throws SQLException { 

    ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql); 

    parameterHandler.setParameters(ps); 

  } 

 

  @Data //采用lombok插件编译 

  public static class Page<E> { 

    private int pageNum; 

    private int pageSize; 

    private int startRow; 

    private int endRow; 

    private long total; 

    private int pages; 

    private List<E> result; 

 

    public Page(int pageNum, int pageSize) { 

      this.pageNum = pageNum; 

      this.pageSize = pageSize; 

      this.startRow = pageNum > 0 ? (pageNum - 1) * pageSize : 0; 

      this.endRow = pageNum * pageSize; 

    } 

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读