java jsp 百度分页_模拟百度分页效果之纯jsp版实例

数据库连接工具类

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

package com.gao.page.utils;

import java.sql.Connection;

import java.sql.DriverManager;

public class DatabaseConnection {

/**

*一个静态方法,返回一个数据库的连接。

*这样达到了对数据库连接统一控制的目的。

*/

public static Connection getConnection()

{

Connection con=null;

String classForName=com.mysql.jdbc.Driver;

String servAndDB=jdbc:mysql://localhost/gaodb;

String user=root;

String pwd=123;

try

{

Class.forName(classForName);

con = DriverManager.getConnection(servAndDB,user,pwd);

}

catch(Exception e)

{

e.printStackTrace();

}

return con;

}

}

Person实体类

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

package com.gao.page;

/**

* @作者   Relieved

* @创建日期   2015年6月14日

* @描述  (person类)

* @版本 V 1.0

*/

public class Person {

private Integer id;

private String name;

private Integer gender;

private String phone;

private Integer age;

private String address;

/**

* @return the id

*/

public Integer getId() {

return id;

}

/**

* @param id the id to set

*/

public void setId(Integer id) {

this.id = id;

}

/**

* @return the name

*/

public String getName() {

return name;

}

/**

* @param name the name to set

*/

public void setName(String name) {

this.name = name;

}

/**

* @return the gender

*/

public Integer getGender() {

return gender;

}

/**

* @param gender the gender to set

*/

public void setGender(Integer gender) {

this.gender = gender;

}

/**

* @return the age

*/

public Integer getAge() {

return age;

}

/**

* @param age the age to set

*/

public void setAge(Integer age) {

this.age = age;

}

/**

* @return the phone

*/

public String getPhone() {

return phone;

}

/**

* @param phone the phone to set

*/

public void setPhone(String phone) {

this.phone = phone;

}

/**

* @return the address

*/

public String getAddress() {

return address;

}

/**

* @param address the address to set

*/

public void setAddress(String address) {

this.address = address;

}

}

数据库连接操作类

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

package com.gao.page;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import com.gao.page.utils.DatabaseConnection;

public class Personbean {

private static Connection con;

//构造方法,获得数据库的连接。

static  {

con=DatabaseConnection.getConnection();

}

/**

* 带分页的查询

* @param pageSize

* @param pageNum

* @return

* @throws Exception

*/

public static List getPersonInf(int pageNum,int pageSize)throws Exception

{

PreparedStatement   pstmt=con.prepareStatement(select * from person limit ?,? );

pstmt.setInt(1,(pageNum-1)*pageSize);

pstmt.setInt(2,pageSize);

ResultSet rst=pstmt.executeQuery();

List ret=new ArrayList();

while(rst.next())

{

Person temp=new Person();

temp.setId(rst.getInt(1));

temp.setName(rst.getString(2));

temp.setGender(rst.getInt(3));

temp.setPhone(rst.getString(4));

temp.setAge(rst.getInt(5));

temp.setAddress(rst.getString(6));

ret.add(temp);

}

return ret;

}

/**

* 获取记录总条数

* @return

* @throws Exception

*/

public static int getPersonCount()throws Exception

{

Statement   pstmt=con.createStatement();

String sql = select * from person;

ResultSet rst=pstmt.executeQuery(sql);

rst.last();//移动到最后一行

return rst.getRow();

}

}

jsp页面代码

1

2

3

4

5

6

7

8

9

10

pageEncoding=UTF-8%>

request.setCharacterEncoding(UTF-8);

String path = request.getContextPath();

String basePath = request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;

%>

员工信息

0){ for(int i=0;i 

Id

姓名

性别

手机号

年龄

地址

暂时没有数据!

项目完整下载路径:http://download.csdn.net/detail/gao36951/8859947

效果图如下

d4611f59a874f1212c44f1fe484497b8.png

d272be1e12355b2e69a2b7f841714a30.png

b6188721233a3aff641d49d3ed1dc90d.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值