好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

java使用三层架构实现电影购票系统

使用三层架构实现电影购票系统,分用户和管理员,用户功能:展示电影,查找电影(模糊查询),查看电影详情,查找场次,购买影票,订制座位,退订影票等功能,界面美观漂亮,逻辑严谨,附加电影评论功能,订票超过五张打0.9折的打折功能。管理员功能:影院的增删改查,场次的增删改查,电影的增删改查,影票管理等。

管理员账号:admin  密码:admin

下载地址: java实现电影购票系统

效果展示图:

登录界面:

用户主界面:

查看热门电影:

点击电影进入查看详情,可以看到该电影的所有评论,可以进行评论。

点击想看电影进入场次界面,可通过影院名查询场次,支持模糊查询。

选好场次进入订座购票界面,购买票并扣取相应钱数,显示余额

返回主页,查看我的影票,选择影票并查看我的评论 ,如未评论可进行评论,评论过可进行修改评论,可退订影票,退订成功钱会返还给用户。

再看查找电影功能,支持模糊查询,也可点击海报进入电影详情

 咱们来展示下basedao的代码:

?

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

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

import java.lang.reflect.field;

import java.sql.connection;

import java.sql.drivermanager;

import java.sql.preparedstatement;

import java.sql.resultset;

import java.sql.resultsetmetadata;

import java.sql.sqlexception;

import java.util.arraylist;

import java.util.list;

 

public class basedao {

 

  public static final string driver = "com.mysql.jdbc.driver" ;

  public static final string url = "jdbc:mysql://localhost:3306/tickets" ;

 

  // 加载驱动,只需加载一次

  static {

  try {

  class .forname(driver);

  } catch (classnotfoundexception e) {

  // todo auto-generated catch block

  e.printstacktrace();

  }

  }

 

  // 获得连接

  public connection getconn() {

  connection conn = null ;

 

  try {

  conn = drivermanager.getconnection(url, "root" , "123456" );

  } catch (sqlexception e) {

  // todo auto-generated catch block

  e.printstacktrace();

  }

  return conn;

  }

 

  // 关闭所有

  public void releaseall(resultset rs, preparedstatement pstmt, connection conn) {

 

  try {

  if (rs != null ) {

  rs.close();

  }

  if (pstmt != null ) {

  pstmt.close();

  }

  if (conn != null ) {

  conn.close();

  }

  } catch (sqlexception e) {

  // todo auto-generated catch block

  e.printstacktrace();

  }

 

  }

 

  // 增删改 封装

  public boolean operupdate(string sql, list<object> params) {

  connection conn = null ;

  preparedstatement pstmt = null ;

  int res = 0 ;

 

  // 获得与数据库的连接对象

  conn = getconn();

 

  try {

 

  pstmt = conn.preparestatement(sql);

 

  if (params != null ) {

  for ( int i = 0 ; i < params.size(); i++) {

 

  pstmt.setobject(i + 1 , params.get(i));

 

  }

 

  }

  // 增刪改的統一方法

 

  res = pstmt.executeupdate();

  //返回的是sql在数据库中影响的行数

  } catch (sqlexception e) {

  // todo auto-generated catch block

  e.printstacktrace();

  } finally {

  releaseall( null , pstmt, conn);

  }

 

  return res > 0 ? true : false ;

 

  }

 

  public <t> list<t> operquery(string sql, list<object> params, class <t> cls) throws exception {

  connection conn = null ;

  preparedstatement pstmt = null ;

  resultset rs = null ;

  list<t> list = new arraylist<t>();

  conn = getconn();

 

  try {

  pstmt = conn.preparestatement(sql);

 

  if (params != null ) {

  for ( int i = 0 ; i < params.size(); i++) {

 

  pstmt.setobject(i + 1 , params.get(i));

 

  }

 

  }

  // 增刪改的統一方法

 

  rs = pstmt.executequery();

  resultsetmetadata rsmd = rs.getmetadata();

  while (rs.next()) {

  t m = cls.newinstance();

 

  for ( int i = 0 ; i < rsmd.getcolumncount(); i++) {

  string col_name = rsmd.getcolumnname(i + 1 );

 

  object value = rs.getobject(col_name);

 

  field field;

 

  field = cls.getdeclaredfield(col_name);

 

  field.setaccessible( true );

  field.set(m, value);

  }

  list.add(m);

  }

  }

 

  catch (sqlexception e) {

  // todo auto-generated catch block

  e.printstacktrace();

  } finally {

  releaseall(rs, pstmt, conn);

  }

  return list;

 

  }

 

}

该项目界面美观,代码封装性良好,逻辑严密,仅供参考。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://blog.csdn.net/zouzong123/article/details/81534635

查看更多关于java使用三层架构实现电影购票系统的详细内容...

  阅读:19次