基于JavaWeb新闻发布系统开发与设计(附源码论文资料)

在这里插入图片描述

基于JavaWeb新闻发布系统开发与设计(附源码论文资料)

1.绪论

1.1.新闻发布系统的开发背景

随着计算机技术的发展,网络技术对我们生活和工作显得月来越重要,特别是现在信息高度发达的今天,人们对最新信息的需求和发布迫切的需要及时性。而动态交互式网页刚好提供了这些功能,本系统就是一个能够在网上实现新闻的网上多用户发布,多栏目管理,实时的进行行为统计和记录的网上交互系统。

新闻发布系统,广泛应用于大型专业网站、政府网站、企业网站等几乎所有的网站上,是将新闻、信息栏目和业界动态等信息集中起来发布、管理、查询等的一种网站应用程序。无论企业网站管理人员身处何地,只要能够上网就能对网站信息进行更新及维护。所有的操作可以通过浏览器完成,不需要掌握其他应用软件,用户不需培训。人寿保险公司也离不开这样的管理。

用信息化手段改造传统产业,提高工作效率已是不可争辩的事实。那么,本系统管理信息系统主要解决的就是企事业单位领导们所关心的人、资源、信息和业务等方面的管理问题。当今时代的两个显著特点就是世界经济一体化和以计算机为代表的信息技术的快速发展。一个组织要在激烈的竞争中保持优势和不断发展,必须对迅速变化的环境灵敏地做出有效地反应。信息管理系统的应用能够提供这种有效的决策支持。

1.2.设计目的与意义

Internet的蓬勃发展,使新闻传播方式发生了巨大的变化,传统的信息传播媒体电视、管波、报纸已经不再是人们茶余饭后的主要精神甜点,人们开始更多的关注网络新闻。由于互联网所容纳的信息量大,内容丰富,信息及时、准确,更有相关信息的全面介绍与比较,大大地方便了人们的阅读,因此在短短几年里,互联网便跻身于众多媒体之间,并具有相当一部分媒体人群。借此东风,新闻网也迅速发展起来,它内容丰富,涉及商业、工业、农业、银行、财政、教育、娱乐和信息等各个产业,信息量大,不仅有时事新闻,还有相关的行业信息,同时新闻网具有互联网所具备的一切特性。在全球网络化、信息化的今天新闻网迅速的发展,大大丰富了人们的生活,不知不觉,它已成为人们生活中不可或缺的重要组成部分。

由于时间有限,加之信息系统开发经验的缺少和编程能力的有限,所以本系统难免存在各种各样的缺点。敬请指导老师能够提出批评和宝贵意见,谢谢!

2.绪论

2.1.绪论

2.1.1 操作可行性

本系统的开发是在三个月的时间内完成的。前期主要是以学习以及收集资料为主,接下来就是对系统的分析,设计数据库,界面,以及中间的连接。对于计算机专业作为毕业设计来说是可行的。

2.1.2 经济可行性

经济可行性主要是对项目的经济效益进行评价。目前,宁夏理工学院已建立了校园网络系统,具备了运行网络平台的MIS的硬件基础,而且本系统是我组成员自行开发,免费帮助设计并实施的。因此开发、设计这套系统的支出费用是学校可以承担的,即经济上是可行的。

2.1.3 技术可行性

技术上的可行性要考虑将来采用的硬件和软件技术能否满足用户提出的要求。基于当前的计算机网络技术和数据技术已成熟,而且管理信息系统(MIS)的各种开发技术也已经相当成熟,并且在各个领域都不乏成熟的案例。所以为宁夏理工学院开发一套网络平台的多用户共享信息的宿舍管理系统在技术上是可行的。

2.2方案的设计与比较

2.2.1 C/S设计结构和B/S设计结构比较

目前网络应用软件运行的模式主要有两类:Client/Server模式,Browser/Server模式。前者的主要的缺点是维护、升级较为麻烦。且要同时开发服务器端和客户端;后者是近几年伴随Internet迅速发展起来的一种技术,B/S模式客户端是一个标准的浏览器,服务器端是web server,而Web server与数据库和应用服务器的紧密结合,使得这种模式的应用范围不断扩大,它已不仅仅用于网上查询,有很多企业部门的业务系统,企业的MIS系统纷纷采用这种模式,它的优点是便于扩展应用、升级维护简便、不需要开发专门的客户端、不需要对用户进行特殊的设置和软件安装,降低了维护成本,客户端只要有浏览器就可以了。

2.2.2 系统模式的设计

本系统的设计是有两种用户,分别是管理员,普通,每种用户给予不同的操作权限。

2.2.3系统设计的技术选择

处于安全性,功能可扩展性。我们采用java ee。
数据库使用开源的Mysql;
服务器采用Tomcat;

2.2.4系统的运行环境

(1).系统:Windows XP及其以上版本
(2).Web服务器:Tomcat6及其以上版本
(3).数据库服务器:Mysql5
(4).浏览器:IE7,8,9、火狐、Chrome

2.3 系统基本功能需求

系统中涉及系统管理员,普通用户两种权限;接下来针对每种权限说明下功能结构;

2.3.1 系统结构

主要功能有:
系统管理员:新闻管理,新闻评论管理,新闻类别管理,友情链接管理(包括普通用户的所有权限)
普通用户:浏览新闻,评论新闻;

2.3.2 系统业务流程图

在这里插入图片描述
在这里插入图片描述

2.4 数据库需求分析

根据上面业务流程图所涉及到的内容,数据库要设计的表有:评论表,友情链接表,新闻表,新闻类别表,管理员表;

2.5 系统目标

本选题系统的设计主要将实现以下目标:
(1).人性化设计:系统界面友好,操作简单;
(2).分类展示各类别的新闻
(3).实现对新闻的管理,新闻评论的管理,新闻类别的管理,友情链接的管理

3.系统概要设计

3.1总体设计

3.1.1 处理流程

一,普通用户
(1),进入系统主界面,浏览新闻,评论新闻;

二,管理员
(1).打开系统,进入系统登录界面,
(2).通过验证后,进入系统管理主界面
(3).用户操作,执行相应的功能,
(4).退出系统。

3.1.2 系统的数据流图

在这里插入图片描述

3.2 系统结构图

在这里插入图片描述
针对本系统的需求,设计出如下面所示的数据项和数据结构:
管理员表:编号,用户名,密码;
新闻表:新闻编号,新闻标题,新闻内容,发布日期,作者,新闻类型,点击量,是否是头条,是否是图片新闻,图片,是否是热点新闻;
新闻类别表:新闻类别编号,新闻类别名称;
新闻评论表:新闻评论编号,被评论新闻,评论内容,用户IP,评论日期;
友情链接表:友情链接编号,友情链接名称,链接地址,联系人邮件;

3.3 数据库设计

(1).系统管理员信息E-R图
在这里插入图片描述

(2). 新闻信息E-R图
在这里插入图片描述
在这里插入图片描述
(5). 新闻评论信息E-R图

在这里插入图片描述
(6). 友情链接信息E-R图
在这里插入图片描述
(7)实体之间的关系图
在这里插入图片描述

3.4逻辑结构设计

1,新闻和新闻类别是多对一关系;
2,评论和新闻是多对一的关系;

3.5 数据库表的设计

(1). 管理员信息表
在这里插入图片描述
(2). 新闻表
在这里插入图片描述
(3). 新闻类别表
在这里插入图片描述
(4). 新闻评论表
在这里插入图片描述
(5). 友情链接表
在这里插入图片描述

4.系统的详细设计与实现

4.1.前台设计实现

4.1.1 主界面设计实现

效果图:
在这里插入图片描述

相关说明:
用户进入系统主界面,可以看到导航有首页,后面跟着各种新闻类别;下面的话,有滚动图片新闻,新闻头条,最近更新新闻,热点新闻,以及各种新闻类别最近更新;下面还有友情链接;

关键代码实现:

查询所有新闻类别:

public List<NewsType> newsTypeList(Connection con)throws Exception{
		List<NewsType> newsTypeList=new ArrayList<NewsType>();
		String sql="select * from t_newsType";
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			NewsType newsType=new NewsType();
			newsType.setNewsTypeId(rs.getInt("newsTypeId"));
			newsType.setTypeName(rs.getString("typeName"));
			newsTypeList.add(newsType);
		}
		return newsTypeList;
	}

查询各种条件的新闻:

public List<News> newsList(Connection con,String sql)throws Exception{
		List<News> newsList=new ArrayList<News>();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			News news=new News();
			news.setNewsId(rs.getInt("newsId"));
			news.setTitle(rs.getString("title"));
			news.setContent(rs.getString("content"));
			news.setPublishDate(DateUtil.formatString(rs.getString("publishDate"), "yyyy-MM-dd HH:mm:ss"));
			news.setAuthor(rs.getString("author"));
			news.setTypeId(rs.getInt("typeId"));
			news.setClick(rs.getInt("click"));
			news.setIsHead(rs.getInt("isHead"));
			news.setImageName(PropertiesUtil.getValue("userImage")+rs.getString("imageName"));
			news.setIsHot(rs.getInt("isHot"));
			newsList.add(news);
		}

查询友情链接:

public List<Link> linkList(Connection con,String sql)throws Exception{
		List<Link> linkList=new ArrayList<Link>();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			Link link=new Link();
			link.setLinkId(rs.getInt("linkId"));
			link.setLinkName(rs.getString("linkName"));
			link.setLinkUrl(rs.getString("linkUrl"));
			link.setLinkEmail(rs.getString("linkUrl"));
			link.setOrderNum(rs.getInt("orderNum"));
			linkList.add(link);
		}
		return linkList;
	}

4.1.2 新闻类别列表页实现

效果图:
在这里插入图片描述
相关说明:
新闻类别列表,上面依然是导航,下面部分,左边是新闻列表,有上下分页,右边有最新新闻,和热点新闻;

关键代码实现:
根据新闻类别id查询新闻

private void newsList(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String typeId=request.getParameter("typeId");
		String page=request.getParameter("page");
		if(StringUtil.isEmpty(page)){
			page="1";
		}
		Connection con=null;
		News s_news=new News();
		if(StringUtil.isNotEmpty(typeId)){
			s_news.setTypeId(Integer.parseInt(typeId));
		}
		try{
			con=dbUtil.getCon();
			int total=newsDao.newsCount(con, s_news,null,null);
			PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(PropertiesUtil.getValue("pageSize")));
			List<News> newestNewsListWithType=newsDao.newsList(con, s_news, pageBean,null,null);
			request.setAttribute("newestNewsListWithType", newestNewsListWithType);
			request.setAttribute("navCode", NavUtil.genNewsListNavigation(newsTypeDao.getNewsTypeById(con, typeId).getTypeName(), typeId));
			request.setAttribute("pageCode", PageUtil.getUpAndDownPagation(total, Integer.parseInt(page), Integer.parseInt(PropertiesUtil.getValue("pageSize")), typeId));
			request.setAttribute("mainPage", "news/newsList.jsp");
			request.getRequestDispatcher("foreground/newsTemp.jsp").forward(request, response);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {

4.1.3 新闻内容页实现

效果图:
在这里插入图片描述

相关说明:
和新闻列表页唯一的不同是左边是具体的新闻内容,下方有 上一篇,下一篇链接,以及用户评论功能;

关键代码实现:

public News getNewsById(Connection con,String newsId)throws Exception{
		String sql="select * from t_news t1,t_newsType t2 where t1.typeId=t2.newsTypeId and t1.newsId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsId);
		ResultSet rs=pstmt.executeQuery();
		News news=new News();
		if(rs.next()){
			news.setNewsId(rs.getInt("newsId"));
			news.setTitle(rs.getString("title"));
			news.setContent(rs.getString("content"));
			news.setPublishDate(DateUtil.formatString(rs.getString("publishDate"), "yyyy-MM-dd HH:mm:ss"));
			news.setAuthor(rs.getString("author"));
			news.setTypeName(rs.getString("typeName"));
			news.setTypeId(rs.getInt("typeId"));
			news.setClick(rs.getInt("click"));
			news.setIsHead(rs.getInt("isHead"));
			news.setIsImage(rs.getInt("isImage"));
			news.setImageName(PropertiesUtil.getValue("userImage")+rs.getString("imageName"));
			news.setIsHot(rs.getInt("isHot"));
		}
		return news;
	}

4.1.4 新闻评论实现

效果图:
在这里插入图片描述

相关说明:
用户在评论文本域中输入评论信息,然后点击“发表评论”,即可提交评论。

关键代码实现:
评论信息添加:

public int commentAdd(Connection con,Comment comment)throws Exception{
		String sql="insert into t_comment values(null,?,?,?,now())";

评论信息查询:

public List<Comment> commentList(Connection con,Comment s_comment,PageBean pageBean,String bCommentDate,String aCommentDate)throws Exception{
		List<Comment> commentList=new ArrayList<Comment>();
		StringBuffer sb=new StringBuffer("select * from t_comment t1,t_news t2 where t1.newsId=t2.newsId");
		if(s_comment.getNewsId()!=-1){
			sb.append(" and t1.newsId="+s_comment.getNewsId());
		}
		if(StringUtil.isNotEmpty(bCommentDate)){
			sb.append(" and TO_DAYS(t1.commentDate)>=TO_DAYS('"+bCommentDate+"')");
		}
		if(StringUtil.isNotEmpty(aCommentDate)){
			sb.append(" and TO_DAYS(t1.commentDate)<=TO_DAYS('"+aCommentDate+"')");
		}
		sb.append(" order by t1.commentDate desc ");
		if(pageBean!=null){
			sb.append(" limit "+pageBean.getStart()+","+pageBean.getPageSize());
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			Comment comment=new Comment();
			comment.setCommentId(rs.getInt("commentId"));
			comment.setNewsId(rs.getInt("newsId"));
			comment.setNewsTitle(rs.getString("title"));
			comment.setContent(rs.getString("content"));
			comment.setUserIP(rs.getString("userIP"));
			comment.setCommentDate(DateUtil.formatString(rs.getString("commentDate"), "yyyy-MM-dd HH:mm:ss"));
			commentList.add(comment);

4.2 后台设计实现

4.2.1 后台登录实现

效果图:
在这里插入图片描述
相关说明:

用户登录后台地址:http://localhost:8080/News/background/login.jsp
则进入新闻发布系统的后台管理界面,用户输入正确的用户和密码。然后点击 登录 按钮,
则进入后台管理主界面;默认的用户名和密码是 admin 123456

关键代码实现:

public User login(Connection con,User user)throws Exception{
		User resultUser=null;
		String sql="select * from t_user where userName=? and password=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, user.getPassword());
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			resultUser=new User();
			resultUser.setUserId(rs.getInt("userId"));
			resultUser.setUserName(rs.getString("userName"));
			resultUser.setPassword(rs.getString("password"));
		}
		return resultUser;
	}
con=dbUtil.getCon();
User user=new User(userName,password);
User currentUser=userDao.login(con, user);
if(currentUser==null){
	request.setAttribute("error", "用户名或者密码错误!");
	request.setAttribute("password", password);
	request.setAttribute("userName", userName);
	request.getRequestDispatcher("/background/login.jsp").forward(request, response);
}else{
	session.setAttribute("currentUser", currentUser);
	request.setAttribute("mainPage", "/background/default.jsp");
	request.getRequestDispatcher("/background/mainTemp.jsp").forward(request, response);
}

4.2.2 后台主界面实现

效果图:
在这里插入图片描述
相关说明:
当管理员输入正确的用户名和密码,则进入系统的主界面;
主界面顶部是 一个Logo,加一些欢迎信息,有安全退出功能,以及显示当前日期时间小功能;左边是菜单栏,包括对各种功能的管理,这个后面会详细的介绍。右边是主题界面;

关键代码:
公共代码foot.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="row-fluid">
	<div class="span12">
		<div class="foot">Copyright © 2013-2024 XXXX 版权所有</div>
	</div>
</div>

公共代码head.jsp

<script type="text/javascript">
	function setDateTime(){
			...
		}
		
		window.setInterval("setDateTime()", 1000);
		
		function logout(){
			if(confirm('您确定要退出系统吗?')){
				window.location.href='${pageContext.request.contextPath}/user?action=logout';
			}
		}
	</script>
<div class="row-fluid">
	<div class="span12">
		<div>
			<div class="headLeft">
				<img src="${pageContext.request.contextPath}/images/logo_back.png"/>
			</div>
			<div class="headRight">
				欢迎管理员:<font color="red">${currentUser.userName }</font>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:logout()">[&nbsp;安全退出&nbsp;]</a>&nbsp;&nbsp;&nbsp;&nbsp;<font id="today" class="currentDateTime"></font>
			</div>
		</div>
	</div>
</div>

mainTemp.jsp
模版主页

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
...
</head>
<script type="text/javascript">
	...
</script>
<body>
<div class="container">
<jsp:include page="/background/common/head.jsp"/>

<div class="row-fluid">
	<div class="span3">
		<div class="newsMenu">
		    <ul>
....
			</ul>
		</div>
	</div>
	<div class="span9">
		<jsp:include page="<%=mainPage %>"></jsp:include>
	</div>
</div>
<jsp:include page="/background/common/foot.jsp"/>
</div>
</body>
</html>

4.2.3 友情链接管理

效果图:
友情链接查询界面:在这里插入图片描述

功能说明:
用户点击“友情链接维护”菜单,则显示右边内容,查询出所有的友情链接,有操作栏-修改和删除友情链接;

友情链接添加界面:
在这里插入图片描述
功能说明:
用户点击“友情链接添加”菜单,则显示右边内容,用户输入表单信息,点击保存友情链接按钮,就可以实现友情链接的添加;

友情链接修改界面:
在这里插入图片描述
功能说明“修改”按钮。则进去修改页面。用户修改表单信息,点击保存友情链接,则完成友情链接修改;

友情链接修改:
在这里插入图片描述
功能说明:
当用户点击“删除”按钮,会有个确认框弹出来,假如用户点击确定,则删除这条友情链接;

关键代码:
友情链接查询:

public List<Link> linkList(Connection con,String sql)throws Exception{
		List<Link> linkList=new ArrayList<Link>();
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			Link link=new Link();
			link.setLinkId(rs.getInt("linkId"));
			link.setLinkName(rs.getString("linkName"));
			link.setLinkUrl(rs.getString("linkUrl"));
			link.setLinkEmail(rs.getString("linkUrl"));
			link.setOrderNum(rs.getInt("orderNum"));
			linkList.add(link);
		}
		return linkList;
	}

友情链接添加:

public int linkAdd(Connection con,Link link)throws Exception{
		String sql="insert into t_link values(null,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, link.getLinkName());
		pstmt.setString(2, link.getLinkUrl());
		pstmt.setString(3, link.getLinkEmail());
		pstmt.setInt(4, link.getOrderNum());
		return pstmt.executeUpdate();
	}

友情链接修改:

public int linkUpdate(Connection con,Link link)throws Exception{
		String sql="update t_link set linkName=?,linkUrl=?,linkEmail=?,orderNum=? where linkId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, link.getLinkName());
		pstmt.setString(2, link.getLinkUrl());
		pstmt.setString(3, link.getLinkEmail());
		pstmt.setInt(4, link.getOrderNum());
		pstmt.setInt(5, link.getLinkId());
		return pstmt.executeUpdate();
	}

通过编号获取友情链接实体:

public Link getLinkById(Connection con,String linkId)throws Exception{
		String sql="select * from t_link where linkId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, linkId);
		ResultSet rs=pstmt.executeQuery();
		Link link=new Link();
		while(rs.next()){
			link.setLinkId(rs.getInt("linkId"));
			link.setLinkName(rs.getString("linkName"));

友情链接删除:

public int linkDelete(Connection con,String linkId)throws Exception{
		String sql="delete from t_link where linkId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, linkId);
		return pstmt.executeUpdate();
	}

4.2.4 新闻类别管理

效果图:
新闻类别查询显示:
在这里插入图片描述
功能说明:
用户点击“新闻类别维护”菜单,则弹出右边内容,新闻类别的展示,及相关操作,“修改”
,“删除”;

新闻类别添加:
在这里插入图片描述
功能说明:
用户点击“新闻类别添加”,则显示右边内容,用户填写 新闻类别名称,然后点击“保存”,则完成新闻类别的添加;

新闻类别修改:
在这里插入图片描述
当用户点击“修改”,则进入新闻类别修改界面,用户修改 新闻类别名称,点击“保存”,则完成新闻类别的修改;

新闻类别删除:
在这里插入图片描述
当用户点击“删除”,会弹出确认框,假如用户点击确定,则删除新闻类别;

关键代码实现:

新闻类别查询:

public List<NewsType> newsTypeList(Connection con)throws Exception{
		List<NewsType> newsTypeList=new ArrayList<NewsType>();
		String sql="select * from t_newsType";
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			NewsType newsType=new NewsType();
			newsType.setNewsTypeId(rs.getInt("newsTypeId"));
			newsType.setTypeName(rs.getString("typeName"));
			newsTypeList.add(newsType);
		}
		return newsTypeList;
	}

新闻类别添加:

public int newsTypeAdd(Connection con,NewsType newsType)throws Exception{
		String sql="insert into t_newsType values(null,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsType.getTypeName());
		return pstmt.executeUpdate();
	}

新闻类别修改:

public int newsTypeUpdate(Connection con,NewsType newsType)throws Exception{
		String sql="update t_newsType set typeName=? where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsType.getTypeName());
		pstmt.setInt(2, newsType.getNewsTypeId());
		return pstmt.executeUpdate();
	}

通过编号获取新闻类别实体:

public NewsType getNewsTypeById(Connection con,String newsTypeId)throws Exception{
		NewsType newsType=new NewsType();
		String sql="select * from t_newsType where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsTypeId);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			newsType.setNewsTypeId(rs.getInt("newsTypeId"));
			newsType.setTypeName(rs.getString("typeName"));
		}
		return newsType;
	}

新闻类别删除:

public int newsTypeDelete(Connection con,String newsTypeId)throws Exception{
		String sql="delete from t_newsType where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsTypeId);
		return pstmt.executeUpdate();
	}

4.2.5 新闻评论管理

效果图:
新闻评论查询:
在这里插入图片描述
功能说明:

用户点击新闻评论维护,则进入 右侧页面,内容是新闻评论的分页显示,支持单个删除和批量删除功能,以及根据评论日期进行查询;

新闻评论删除:
在这里插入图片描述

功能说明:
用户点击删除,弹出确认框,假如用户点击确定,则删除该评论;
在这里插入图片描述
用户选择要删除评论,然后点击批量删除,弹出确认框,假如用户点击确定,则实现把选中的评论都删除,即批量删除功能;

关键代码实现:

评论删除:

public int commentDelete(Connection con,String commentIds)throws Exception{
		String sql="delete from t_comment where commentId in ("+commentIds+")";
		PreparedStatement pstmt=con.prepareStatement(sql);
		return pstmt.executeUpdate();
	}

评论查询:

public List<Comment> commentList(Connection con,Comment s_comment,PageBean pageBean,String bCommentDate,String aCommentDate)throws Exception{
		List<Comment> commentList=new ArrayList<Comment>();
		StringBuffer sb=new StringBuffer("select * from t_comment t1,t_news t2 where t1.newsId=t2.newsId");
		if(s_comment.getNewsId()!=-1){
			sb.append(" and t1.newsId="+s_comment.getNewsId());
		}
		if(StringUtil.isNotEmpty(bCommentDate)){
			sb.append(" and TO_DAYS(t1.commentDate)>=TO_DAYS('"+bCommentDate+"')");
		}
		if(StringUtil.isNotEmpty(aCommentDate)){
			sb.append(" and TO_DAYS(t1.commentDate)<=TO_DAYS('"+aCommentDate+"')");
		}
		sb.append(" order by t1.commentDate desc ");
		if(pageBean!=null){
			sb.append(" limit "+pageBean.getStart()+","+pageBean.getPageSize());
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			Comment comment=new Comment();
			comment.setCommentId(rs.getInt("commentId"));

4.2.6 新闻管理

效果图:
新闻查询实现:
在这里插入图片描述
功能说明:
用户点击 新闻维护 菜单,则显示右侧内容,主要内容有新闻内容的分页实现,有根据新闻标题,和发布日期进行查询;有操作栏,可以对单条记录进行修改和删除;

新闻添加实现:
在这里插入图片描述
功能说明:
用户点击新闻添加菜单,右侧出现 新闻添加页面,用户填写好表单信息,点击“保存”按钮,则完成“新闻添加”功能;

新闻修改:
在这里插入图片描述
功能说明:
用户点击“修改”,则进入新闻修改页面,用户编辑表单,编辑完,点击“保存新闻”,则实现新闻修改操作;

新闻删除:
在这里插入图片描述
功能说明:
用户点击“删除”按钮,则弹出确认框,假如用户点击确定按钮,则删除新闻;

关键代码实现:
新闻总记录数查询:

public int newsCount(Connection con,News s_news,String s_bPublishDate,String s_aPublishDate)throws Exception{
		StringBuffer sb=new StringBuffer("select count(*) as total from t_news");
		if(s_news.getTypeId()!=-1){
			sb.append(" and typeId="+s_news.getTypeId());
		}
		if(StringUtil.isNotEmpty(s_news.getTitle())){
			sb.append(" and title like '%"+s_news.getTitle()+"%'");
		}
		if(StringUtil.isNotEmpty(s_bPublishDate)){
			sb.append(" and TO_DAYS(publishDate)>=TO_DAYS('"+s_bPublishDate+"')");
		}
		if(StringUtil.isNotEmpty(s_aPublishDate)){
			sb.append(" and TO_DAYS(publishDate)<=TO_DAYS('"+s_aPublishDate+"')");
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
		ResultSet rs=pstmt.executeQuery();

新闻查询:

public List<News> newsList(Connection con,News s_news,PageBean pageBean,String s_bPublishDate,String s_aPublishDate)throws Exception{
		List<News> newsList=new ArrayList<News>();
		StringBuffer sb=new StringBuffer("select * from t_news t1,t_newsType t2 where t1.typeId=t2.newsTypeId ");
		....
		PreparedStatement pstmt=con.prepareStatement(sb.toString());
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			News news=new News();
			news.setNewsId(rs.getInt("newsId"));
			news.setTitle(rs.getString("title"));
			news.setContent(rs.getString("content"));
			news.setPublishDate(DateUtil.formatString(rs.getString("publishDate"), "yyyy-MM-dd HH:mm:ss"));
			news.setAuthor(rs.getString("author"));
			news.setTypeId(rs.getInt("typeId"));
			news.setTypeName(rs.getString("typeName"));
			news.setClick(rs.getInt("click"));
			news.setIsHead(rs.getInt("isHead"));
			news.setImageName(PropertiesUtil.getValue("userImage")+rs.getString("imageName"));
			news.setIsHot(rs.getInt("isHot"));
			newsList.add(news);

新闻添加:

public int newsAdd(Connection con,News news)throws Exception{
		String sql="insert into t_news values(null,?,?,now(),?,?,0,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, news.getTitle());
		pstmt.setString(2, news.getContent());
		pstmt.setString(3, news.getAuthor());
		pstmt.setInt(4, news.getTypeId());
		pstmt.setInt(5, news.getIsHead());
		pstmt.setInt(6, news.getIsImage());
		pstmt.setString(7, news.getImageName());
		pstmt.setInt(8, news.getIsHot());
		return pstmt.executeUpdate();
	}

新闻修改:

public int newsUpdate(Connection con,News news)throws Exception{
		String sql="update t_news set title=?,content=?,author=?,typeId=?,isHead=?,isImage=?,imageName=?,isHot=? where newsId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, news.getTitle());
		pstmt.setString(2, news.getContent());
		pstmt.setString(3, news.getAuthor());

新闻删除:

public int newsDelete(Connection con,String newsId)throws Exception{
		String sql="delete from t_news where newsId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsId);
		return pstmt.executeUpdate();
	}

4.2.7 刷新服务器缓存功能

功能介绍:系统的某些数据是存放在application里的,比如新闻类别信息,热门新闻等,每当我们更新了后台,我们就需要刷新下服务器缓存,来实现新闻系统的数据的最新展现;

效果图:
在这里插入图片描述
功能说明:
用户点击“刷新服务器缓存”,弹出“系统刷新成功”,则说明 执行成功;

关键代码实现:

刷新缓存:

private void refreshSystem(ServletContext application){
		Connection con=null;
		try{
			con=dbUtil.getCon();
			
			List<NewsType> newsTypeList=newsTypeDao.newsTypeList(con);
			application.setAttribute("newsTypeList", newsTypeList);
			
			String sql="select * from t_news order by publishDate desc limit 0,8 ";
			List<News> newestNewsList=newsDao.newsList(con, sql);
			application.setAttribute("newestNewsList", newestNewsList);
			
			sql="select * from t_news order by click desc limit 0,8";
			List<News> hotNewsList=newsDao.newsList(con, sql);
			application.setAttribute("hotNewsList", hotNewsList);

Servlet调用:

@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session=request.getSession();
		ServletContext application=session.getServletContext();
		this.refreshSystem(application);
		JSONObject result=new JSONObject();
		result.put("success", true);
		try {
			ResponseUtil.write(result, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

5.结论

经过一段时间的努力,毕业设计终于一段落。本文是关于新闻发布系统的文稿设计,通过阅读本论文可以对本系统有一定的了解。本文介绍了系统开发所用到的技术,编程语言,卡法环境等。同时在做了分析调查后,对本系统做了详细的需求分析。然后对系统的概要设计以及详细设计也做了详细的说明,包括系统的前台设计,数据逻辑层设计以及后台数据库设计。

系统的主要特点有:人性化设计,界面友好,简洁,大方,操作简单方便,权限操作
虽然系统设计已经暂告一个段落,但由于本人的能力有限,再加上知识欠缺,以及对的业务不甚熟悉,所以在很多方面还存在着不足,如在系统需求分析方面还有很多方面没有考虑到,而且在具体实现各个功能的时候也存在一定的局限性。比如测试功能不完善,用户界面功能太简单、系统的界面不是太美观,系统安全性考虑不充分等等。所有本系统还有很多地方有待完善。

7.参考文献

[1]网星工作室,Dreamweaver MX,北京希望电子出版社,2002:10-70
[2]薛小龙,JSP典型系统实战与解析,电子工业出版社,2007:90-96
[3]管西京,JSP+MySql动态网站案例开发,电子工业出版社,2008:76-101
[4]程舒通,学校网站动态技术的开发.,《南宁职业技术学院学报》2006 1 :13-14
[5]Ralph R. Young 著,韩柯、耿民 等译,《有效需求实践》,机械工业出版社
[6]张海藩 ,软件工程导论学习辅导[M],清华大学出版社,2004-9-1
[7]李刚,疯狂Java讲义(第3版)电子工业出版社 ,2014-7-1
[8]李兴华,Java Web开发实战经典基础篇,清华大学出版社,2010-8-1

8.源码获取

精彩专栏推荐订阅:在下方专栏👇🏻

Java精品项目源码大全
https://blog.csdn.net/bruceliu_code/category_9538286.html

欢迎大家点赞收藏关注评论啦 、查看下方二维码👇🏻获取联系方式👇🏻
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源码小哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值