在线小说网站的设计与实现附源码.docx
- 文档编号:12128055
- 上传时间:2023-04-17
- 格式:DOCX
- 页数:27
- 大小:71.90KB
在线小说网站的设计与实现附源码.docx
《在线小说网站的设计与实现附源码.docx》由会员分享,可在线阅读,更多相关《在线小说网站的设计与实现附源码.docx(27页珍藏版)》请在冰豆网上搜索。
在线小说网站的设计与实现附源码
在线小说网站的设计与实现(附源码)
在线小说网站的设计与实现(附源码)最近在做一个课程设计,在线小说网站的设计,以下是课题要求,需要项目练手的童鞋可以试试身手。
由于最近新学了JavaEE,所以采用了jsp+servlet来写,前端部分用了少量的js和jQuery处理,数据库用了MySQL,开发平台是myeclipse。
发布文章时直接插入数据库会没有分段,这里的解决办法是引入第三方工具wangEditor(wangEditor是一款基于JavaScript和css开发的html富文本编辑器,开源免费。
产品第一版发布于2014年11月。
首先数据库的设计结构:
[sql]viewplaincopy在CODE上查看代码片派生到我的代码片
/*
NavicatMySQLDataTransfer
SourceServer:
blog
SourceServerVersion:
50528SourceHost:
localhost:
3306SourceDatabase:
novel
TargetServerType:
MYSQL
TargetServerVersion:
50528
FileEncoding:
65001
Date:
2016-12-3116:
04:
07
*/
SETFOREIGN_KEY_CHECKS=0;
--------------------------------Tablestructureforadmin
------------------------------DROPTABLEIFEXISTS`admin`;CREATETABLE`admin`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`adminName`varchar(255)NOTNULL,
`adminPassword`varchar(255)NOTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=2DEFAULTCHARSET=utf8;
------------------------------
--Tablestructureforauthor
------------------------------
DROPTABLEIFEXISTS`author`;
CREATETABLE`author`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`authorName`varchar(255)NOTNULL,
`authorPassword`varchar(255)NOTNULL,
`authorEmail`varchar(255)DEFAULTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=22DEFAULTCHARSET=utf8;
------------------------------
--Tablestructureforcomment
------------------------------
DROPTABLEIFEXISTS`comment`;
CREATETABLE`comment`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`context`text,
`createdTime`datetimeDEFAULTNULL,
`readerName`varchar(255)DEFAULTNULL,
`novelId`int(11)DEFAULTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=67DEFAULTCHARSET=utf8;
------------------------------
--Tablestructureforgenre
------------------------------
DROPTABLEIFEXISTS`genre`;
CREATETABLE`genre`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`name`varchar(255)DEFAULTNULL,
`sort`int(11)DEFAULTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=14DEFAULTCHARSET=utf8;
------------------------------
--Tablestructurefornovel
------------------------------
DROPTABLEIFEXISTS`novel`;
CREATETABLE`novel`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`title`varchar(255)NOTNULL,
`context`textNOTNULL,
`createdTime`datetimeDEFAULTNULL,
`genreId`int(11)DEFAULTNULL,
`voteNumber`int(11)NOTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=160DEFAULTCHARSET=utf8;
------------------------------
--Tablestructureforreader
------------------------------
DROPTABLEIFEXISTS`reader`;
CREATETABLE`reader`(
`id`int(11)NOTNULLAUTO_INCREMENT,
`readerName`varchar(255)NOTNULL,
`readerPassword`varchar(255)NOTNULL,
`readerEmail`varchar(255)DEFAULTNULL,
PRIMARYKEY(`id`)
)ENGINE=InnoDBAUTO_INCREMENT=22DEFAULTCHARSET=utf8;
项目的大致结构如图:
后台其他导航页面基本雷同,这里不做一一介绍。
后台管理员登录处理代码:
[java]viewplaincopy在CODE上查看代码片派生到我的代码片
publicclassAdmin{
Connconn=newConn();
/**
*判断登陆用户是否合法
*@paramadminName
*@paramadminPassword
*@return
*@throwsSQLException
*/
publicbooleanisExist(StringadminName,StringadminPassword)throwsSQLException{
booleanresult=false;
AdminInfoainfo=newAdminInfo();
Stringsql="select*fromadminawhereadminName='"+adminName+"'and
adminPassword='"+adminPassword+"'";
System.out.println(sql);
ResultSetrs=conn.executeQuery(sql);
if(rs.next()){
ainfo.setAdminName(rs.getString("adminName"));
ainfo.setAdminPassword(rs.getString("adminPassword"));
result=true;
}
conn.close();
returnresult;
}
}
小说展示,管理,增加,删除,更新的代码处理:
[java]viewplaincopy在CODE上查看代码片派生到我的代码片
publicclassNovel{
Connconn=newConn();
/**
*获取小说列表
*@paramkeyword
*@return
*@throwsSQLException
*/
publicList
List
Stringsql="selectn.*,g.nameasgenreNamefromnovelnleftjoingenregon
n.genreId=g.id";
if(DataValidator.isNullOrEmpty(keyword)){
sql=sql+"orderbyiddesc";
}else{
sql=sql+"wheren.titlelike'%"+keyword+"%'orderbyiddesc";
}
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
NovelInfoninfo=newNovelInfo();
ninfo.setId(rs.getInt("Id"));
ninfo.setTitle(rs.getString("Title"));
ninfo.setContext(rs.getString("Context"));
ninfo.setCreatedTime(rs.getDate("CreatedTime"));
ninfo.setGenreId(rs.getInt("GenreId"));
ninfo.setGenreName(rs.getString("genreName"));
ninfo.setVoteNumber(rs.getInt("voteNumber"));
list.add(ninfo);
}
conn.close();
returnlist;
}
/**
*获取某分类下的小说列表
*@paramclassId
*@return
*@throwsSQLException
*/
publicList
List
Stringsql="selectn.*,g.nameasgenreNamefromnovelnleftjoingenregon
n.genreId=g.id"
+"wheren.genreId="+genreId+"orderbyiddesc";
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
NovelInfoinfo=newNovelInfo();
info.setId(rs.getInt("Id"));
info.setTitle(rs.getString("Title"));
info.setContext(rs.getString("Context"));
info.setCreatedTime(rs.getDate("CreatedTime"));
info.setGenreId(rs.getInt("GenreId"));
info.setGenreName(rs.getString("genreName"));
info.setVoteNumber(rs.getInt("voteNumber"));
list.add(info);
}
conn.close();
returnlist;
}
/**
*根据ID获取小说
*@paramid
*@return
*@throwsSQLException
*/
publicNovelInfogetNovelInfo(intid)throwsSQLException{
NovelInfoinfo=newNovelInfo();
Stringsql="selectn.*,g.nameasgenreNamefromnovelnleftjoingenregon
n.genreId=g.idwheren.id="+id+"";
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
info.setId(rs.getInt("Id"));
info.setTitle(rs.getString("Title"));
info.setContext(rs.getString("Context"));
info.setCreatedTime(rs.getDate("CreatedTime"));
info.setGenreId(rs.getInt("GenreId"));
info.setGenreName(rs.getString("genreName"));
info.setVoteNumber(rs.getInt("voteNumber"));
}
conn.close();
returninfo;
}
/**
*写入新小说
*
*@paraminfo
*@return
*/
publicintinsert(NovelInfoinfo){
Stringsql="insertintonovel(title,conText,createdTime,genreId,voteNumber)values";
sql=sql+"('"+info.getTitle()+"','"+info.getContext()+"',now(),'"+info.getGenreId()+"',"+info.getVot
eNumber()+")";
intresult=0;
System.out.println(sql);
result=conn.executeUpdate(sql);
conn.close();
returnresult;
}
/**
*更新小说
*@paraminfo
*@return
*/
publicintupdate(NovelInfoinfo){
Stringsql="updatenovelset"+"
Title='"+info.getTitle()+"',Context='"+info.getContext()+"',"
+"genreId='"+info.getGenreId()+"'whereid="+info.getId()+"";
intresult=0;
System.out.println(sql);
result=conn.executeUpdate(sql);
conn.close();
returnresult;
}
/**
*删除小说
*@paramid
*@return
*/
publicintdelete(intid){
Stringsql="deletefromnovelwhereid="+id+"";
intresult=0;
result=conn.executeUpdate(sql);
conn.close();
returnresult;
}
/**
*增加票数
*@return
*/
publicintaddVote(intnum){
return0;
}
}
小说评论展示,管理,增加,删除,更新的代码处理:
[java]viewplaincopy在CODE上查看代码片派生到我的代码片
publicclassComment{
Connconn=newConn();
/**
*获取评论列表
*@return
*@throwsSQLException
*/
publicList
List
Stringsql="select*fromcommentorderbyiddesc";
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
CommentInfoinfo=newCommentInfo();
info.setId(rs.getInt("Id"));
info.setContext(rs.getString("Context"));
info.setNovelId(rs.getInt("NovelId"));
info.setCreatedTime(rs.getDate("CreatedTime"));
info.setReaderName(rs.getString("ReaderName"));
list.add(info);
System.out.print(list);
}
conn.close();
returnlist;
}
/**
*
*@paramclassId
*@return
*@throwsSQLException
*/
publicCommentInfogetCommentInfo(intid)throwsSQLException{
CommentInfoinfo=newCommentInfo();
Stringsql="select*fromCommentcwhereid="+id+"";
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
info.setId(rs.getInt("Id"));
info.setContext(rs.getString("Context"));
info.setNovelId(rs.getInt("NovelId"));
info.setCreatedTime(rs.getDate("CreatedTime"));
info.setReaderName(rs.getString("ReaderName"));
}
conn.close();
returninfo;
}
/**
*获取某小说下的评论
*@paramid
*@return
*@throwsSQLException
*/
publicList
List
Stringsql="select*fromcommentwherenovelId="+novelid+"orderbyiddesc";
ResultSetrs=conn.executeQuery(sql);
while(rs.next()){
CommentInfoinfo=newCommentInfo();
info.setId(rs.getInt("Id"));
info.setContext(rs.getString("Context"));
info.setNovelId(rs.getInt("NovelId"));
info.setCreatedTime(rs.getDate("CreatedTime"));
info.setReaderName(rs.getString("ReaderName"));
list.add(info);
}
conn.close();
returnlist;
}
/**
*插入评论
*@paraminfo
*@return
*/
publicintinsert(CommentInfoinfo){
Stringsql="insertintoComment(Context,CreatedTime,readerName,novelId)values";
sql=sql+"('"+info.getContext()+"',now(),'"+info.getReaderName()+"',"+info.getNovelId()+")";
intresult=0;
System.out.println(sql);
result=conn.executeUpdate(sql);
conn.close();
returnresult;
}
/**
*更新评论
*@paraminfo
*@return
*/
publicintupdate(CommentInfoinfo){
Stringsql="updateCommentset"+"Context='"+info.getContext()+"',novelId='"+info.getNovelId()+"',"
+
"CreatedTime='"+info.getCreatedTime()+"',readerName='"+info.getReaderName()+"'where
id="+info.getId()+"";
intresult=0;
Sys
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 在线 小说 网站 设计 实现 源码