MySQL---数据库从入门走向大神系列(十六)-JavaWeb分页技术实例演示1

分页,是一种将所有数据分段展示给用户的技术.用户每次看到的不 是全部数据,而是其中的一部分,如果在其中没有找到自己想要的内容,用户可以通过指定页码或是点上/下一页的方式进行翻页。

本例演示静态分页,也就是先设置好每页显示10行,再根据总行数,来算出总页数,将所有页数的页号都显示出来。

相关算法(技术):

像这样:


点击哪一页就显示哪一页的内容。

数据库数据:

数据库的表和数据在这一篇博客中已经准备好了:

http://blog.csdn.net/qq_26525215/article/details/52212571

DAO层:

接口:

实现类:

C3p0配置文件c3p0-config.xml:

1.   <c3p0-config>

2.       <!-- 默认配置,如果没有指定则使用这个配置 -->

3.       <default-config>

4.           <property name="driverClass">com.mysql.jdbc.Driver</property>

5.           <property name="jdbcUrl">

6.               <![CDATA[jdbc:mysql://127.0.0.1:3306/hncu?useUnicode=true&characterEncoding=UTF-8]]>

7.           </property>

8.           <property name="user">root</property>

9.           <property name="password">1234</property>

10.           <!-- 初始化池大小 -->

11.           <property name="initialPoolSize">2</property>

12.           <!-- 最大空闲时间 -->

13.           <property name="maxIdleTime">30</property>

14.           <!-- 最多有多少个连接 -->

15.           <property name="maxPoolSize">10</property>

16.           <!-- 最少几个连接 -->

17.          <property name="minPoolSize">2</property>

18.           <!-- 每次最多可以执行多少个批处理语句 -->

19.           <property name="maxStatements">50</property>

20.       </default-config>

21.       <!-- 命名的配置 -->

22.       <named-config name="demo">

23.           <property name="driverClass">com.mysql.jdbc.Driver</property>

24.           <property name="jdbcUrl"><![CDATA[jdbc:mysql://127.0.0.1:3306/hncu?useUnicode=true&characterEncoding=UTF-8]]></property>

25.           <property name="user">root</property>

26.           <property name="password">1234</property>

27.           <property name="acquireIncrement">5</property><!-- 如果池中数据连接不够时一次增长多少个 -->

28.           <property name="initialPoolSize">100</property>

29.           <property name="minPoolSize">50</property>

30.           <property name="maxPoolSize">1000</property>

31.           <property name="maxStatements">0</property>

32.           <property name="maxStatementsPerConnection">5</property> <!-- he's important, but there's only one of him -->

33.       </named-config>

34.   </c3p0-config>

C3p0数据库连接池:

service层:

接口:

实现类

index.jsp:

show.jsp:

table.css:

web.xml:

PageServlet.java:

演示结果:


需要的第三方扩展包:


链接:

https://github.com/chenhaoxiang/Java/tree/master/Database-support-package

完整项目代码链接:

https://github.com/chenhaoxiang/Java/tree/master/myPagesDividedWeb

---------------------

作者:谙忆

来源:CSDN

原文:https://blog.csdn.net/qq_26525215/article/details/52222472

版权声明:本文为博主原创文章,转载请附上博文链接!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容