在线⼩说⽹站的设计与实现(附源码)最近在做⼀个课程设计,在线⼩说⽹站的设计,以下是课题要求,需要项⽬练⼿的童鞋可以试试⾝⼿。
由于最近新学了JavaEE,所以采⽤了jsp+servlet来写,前端部分⽤了少量的和处理,⽤了,开发平台是myeclipse。⾸先数据库的设计结构:
[sql]
01. /*
02. Navicat MySQL Data Transfer
03.
04. Source Server : blog
05. Source Server Version : 50528
06. Source Host : localhost:3306
07. Source Database : novel
08.
09. Target Server Type : MYSQL
10. Target Server Version : 50528
11. File Encoding : 65001
12.
13. Date: 2016-12-31 16:04:07
14. */
15.
16. SET FOREIGN_KEY_CHECKS=0;
17.
18. -- ----------------------------
19. -- Table structure for admin
20. -- ----------------------------
21. DROP TABLE IF EXISTS `admin`;
22. CREATE TABLE `admin` (
23. `id` int(11) NOT NULL AUTO_INCREMENT,
24. `adminName` varchar(255) NOT NULL,
25. `adminPassword` varchar(255) NOT NULL,
26. PRIMARY KEY (`id`)
27. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
28.
29. -- ----------------------------
30. -- Table structure for author
31. -- ----------------------------
32. DROP TABLE IF EXISTS `author`;
33. CREATE TABLE `author` (
34. `id` int(11) NOT NULL AUTO_INCREMENT,
35. `authorName` varchar(255) NOT NULL,
36. `authorPassword` varchar(255) NOT NULL,
37. `authorEmail` varchar(255) DEFAULT NULL,
38. PRIMARY KEY (`id`)
39. ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;
40.
41. -- ----------------------------
42. -- Table structure for comment
43. -- ----------------------------
44. DROP TABLE IF EXISTS `comment`;
45. CREATE TABLE `comment` (
46. `id` int(11) NOT NULL AUTO_INCREMENT,
47. `context` text,
48. `createdTime` datetime DEFAULT NULL,
49. `readerName` varchar(255) DEFAULT NULL,
50. `novelId` int(11) DEFAULT NULL,
51. PRIMARY KEY (`id`)
52. ) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8;
53.
54. -- ----------------------------
55. -- Table structure for genre
56. -- ----------------------------
57. DROP TABLE IF EXISTS `genre`;
58. CREATE TABLE `genre` (
59. `id` int(11) NOT NULL AUTO_INCREMENT,
60. `name` varchar(255) DEFAULT NULL,
61. `sort` int(11) DEFAULT NULL,
62. PRIMARY KEY (`id`)
63. ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
64.
65. -- ----------------------------
66. -- Table structure for novel
67. -- ----------------------------
68. DROP TABLE IF EXISTS `novel`;
69. CREATE TABLE `novel` (
70. `id` int(11) NOT NULL AUTO_INCREMENT,
71. `title` varchar(255) NOT NULL,
72. `context` text NOT NULL,
73. `createdTime` datetime DEFAULT NULL,
74. `genreId` int(11) DEFAULT NULL,
75. `voteNumber` int(11) NOT NULL,
76. PRIMARY KEY (`id`)
77. ) ENGINE=InnoDB AUTO_INCREMENT=160 DEFAULT CHARSET=utf8;
78.
79. -- ----------------------------
80. -- Table structure for reader
81. -- ----------------------------
82. DROP TABLE IF EXISTS `reader`;
83. CREATE TABLE `reader` (
84. `id` int(11) NOT NULL AUTO_INCREMENT,
85. `readerName` varchar(255) NOT NULL,
86. `readerPassword` varchar(255) NOT NULL,
87. `readerEmail` varchar(255) DEFAULT NULL,
88. PRIMARY KEY (`id`)
89. ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;免费平台源码资源网
项⽬的⼤致结构如图:
由于功能有点多,这⾥先介绍后台的实现,管理后台和前台互不交涉。
登录界⾯
后台主页:
1,⼩说管理
2,作者管理:
3,增加分类
后台其他导航页⾯基本雷同,这⾥不做⼀⼀介绍。
后台管理员登录处理代码:
[java]
01. public class Admin {
02. Conn conn=new Conn();
03. /**
04. * 判断登陆⽤户是否合法
05. * @param adminName
06. * @param adminPassword
07. * @return
08. * @throws SQLException
09. */
10. public boolean isExist(String adminName,String adminPassword)throws SQLException{
11. boolean result=false;
12. AdminInfo ainfo=new AdminInfo();
13. String sql="select * from admin a where adminName='"+adminName+"'and adminPassword='"+adminPassword+"'";
14. System.out.println(sql);
15. ResultSet uteQuery(sql);
16. ()){
17. ainfo.String("adminName"));
18. ainfo.String("adminPassword"));
19. result=true;
20. }
21. conn.close();
22. return result;
23. }
24. }
⼩说展⽰,管理,增加,删除,更新的代码处理:
[java]
01. public class Novel {
02. Conn conn=new Conn();
03. /**
04. * 获取⼩说列表
05. * @param keyword
06. * @return
07. * @throws SQLException
08. */
09.
10. public List<NovelInfo>getList(String keyword)throws SQLException{
11. List<NovelInfo> list=new ArrayList<NovelInfo>();
12.
13. String sql="select n.*,g.name as genreName from novel n left join genre g Id=g.id";
14. if(DataValidator.isNullOrEmpty(keyword)){
15. sql=sql+ " order by id desc";
16. }else{
17. sql=sql+" where n.title like '%"+keyword+"%' order by id desc";
18. }
19. ResultSet uteQuery(sql);
20. ()){
21. NovelInfo ninfo=new NovelInfo();
22. ninfo.Int("Id"));
23. ninfo.String("Title"));
24. ninfo.String("Context"));
25. ninfo.Date("CreatedTime"));
26. ninfo.Int("GenreId"));
27. ninfo.String("genreName"));
28. ninfo.Int("voteNumber"));
29. list.add(ninfo);
30. }
31. conn.close();
32. return list;
33. }
34. /**
35. * 获取某分类下的⼩说列表
36. * @param classId
37. * @return
38. * @throws SQLException
39. */
40. public List<NovelInfo> getListBygenreId(int genreId) throws SQLException{
41. List<NovelInfo> list=new ArrayList<NovelInfo>();
42. String sql="select n.*,g.name as genreName from novel n left join genre g Id=g.id"
43. + " Id="+genreId+" order by id desc";
44. ResultSet uteQuery(sql);
45. ()){
46. NovelInfo info=new NovelInfo();
47. info.Int("Id"));
48. info.String("Title"));
49. info.String("Context"));
50. info.Date("CreatedTime"));
51. info.Int("GenreId"));
52. info.String("genreName"));
53. info.Int("voteNumber"));
54. list.add(info);
55. }
56. conn.close();
57. return list;
58. }
59. /**
60. * 根据ID获取⼩说
61. * @param id
62. * @return
63. * @throws SQLException
64. */
65. public NovelInfo getNovelInfo(int id) throws SQLException{
66. NovelInfo info=new NovelInfo();
67. String sql="select n.*,g.name as genreName from novel n left join genre g Id=g.id where n.id="+id+"";
68. ResultSet uteQuery(sql);
69. ()){
70. info.Int("Id"));
71. info.String("Title"));
72. info.String("Context"));
73. info.Date("CreatedTime"));
74. info.Int("GenreId"));
75. info.String("genreName"));
76. info.Int("voteNumber"));
77. }
78. conn.close();
79. return info;
80. }
81. /**
82. * 写⼊新⼩说
83. *
84. * @param info
85. * @return
86. */
87. public int insert(NovelInfo info){
88. String sql="insert into novel(title,conText,createdTime,genreId,voteNumber)values";
89. sql=sql+"('"+Title()+"','"+Context()+"',now(),'"+GenreId()+"',"+VoteNumber()+")";
90. int result=0;
91. System.out.println(sql);
92. uteUpdate(sql);
93. conn.close();
94. return result;
95. }
96.
97. /**
98. *更新⼩说
99. * @param info
100. * @return
101. */
102. public int update(NovelInfo info){
103. String sql="update novel set "+" Title='"+Title()+"',Context='"+Context()+"'," 104. + "genreId='"+GenreId()+"'where id="+Id()+"";
105. int result=0;
106. System.out.println(sql);
107. uteUpdate(sql);
108. conn.close();
109. return result;
110. }
111. /**
112. * 删除⼩说
113. * @param id
114. * @return
115. */
116.
117. public int delete(int id){
118. String sql="delete from novel where id="+id+"";
119. int result=0;
120. uteUpdate(sql);
121. conn.close();
122. return result;
123. }
124. /**
125. * 增加票数
126. * @return
127. */
128. public int addVote(int num){
129.
130. return0;
131.
132. }
133. }
⼩说评论展⽰,管理,增加,删除,更新的代码处理:
[java]
01. public class Comment {
02. Conn conn=new Conn();
03. /**
04. * 获取评论列表
05. * @return
06. * @throws SQLException
07. */
08. public List<CommentInfo> getList() throws SQLException{
09. List<CommentInfo> list=new ArrayList<CommentInfo>();
10. String sql="select * from comment order by id desc";
11. ResultSet uteQuery(sql);
12. ()){
13. CommentInfo info=new CommentInfo();
14. info.Int("Id"));
15. info.String("Context"));
16. info.Int("NovelId"));
17. info.Date("CreatedTime"));
18. info.String("ReaderName"));
19. list.add(info);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论