一 模块需求细化
管理员可以负责公告的增删改查。所有的用户都具备公告的查阅功能。
具有公告权限的用户可以负责公告的发布,公告发布后所有的用户都需要查看。
每一个用户后可以显示所有未读公告的数量。
二 模块相关数据库实现

输入表
公告表:news
公告阅读记录:member_news
输出表
公告表:news
三 公告管理界面设计
1 添加公告管理页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://www.ptpress.com.cn/c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
String addUrl = basePath + "pages/back/news/NewsServletBack/add" ;
%>
<html>
<head>
<base href="<%=basePath%>">
<title>CRM管理系统</title>
<jsp:include page="/pages/plugins/import_file.jsp"/>
<link href="css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath%>js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/select-ui.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/editor/kindeditor.js"></script>
<script type="text/javascript" src="<%=basePath%>js/pages/back/news/news_add.js"></script>
<script type="text/javascript">
KE.show({
id : 'news.note'
});
</script>
</head>
<body>
<div class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="main.html" target="_top">首页</a></li>
<li><a href="#">系统设置</a></li>
</ul>
</div>
<div class="formbody">
<div id="usual1" class="usual">
<div class="itab">
<ul>
<li><a href="#tab1" class="selected">发布公告通知</a></li>
</ul>
</div>
<div id="tab1" class="tabson">
<div class="formtext">
Hi,<b>${mid}</b>,欢迎您试用信息发布功能!
</div>
<form action="<%=addUrl%>" method="post" id="myform">
<ul class="forminfo">
<li><label>公告标题<b>*</b></label>
<input id="news.title" name="news.title" type="text" class="dfinput" placeholder="请输入公告标题" style="width:518px;" /></li>
<li><label>公告分类<b>*</b></label>
<div class="vocation">
<select class="select1" id="news.type" name="news.type">
<option value="0">普通通知</option>
<option value="1">重要通知</option>
</select>
</div></li>
<li><label>通知内容<b>*</b></label>
<textarea name="news.note" id="news.note" style="width:700px;height:250px;visibility:hidden;"></textarea>
</li>
<li><label>
</label><input name="" type="submit" class="btn" value="马上发布" /></li>
</ul>
</form>
</div>
</div>
</div>
</body>
</html>2 公告管理界面设计效果

3 公告列表页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://www.ptpress.com.cn/c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>CRM管理系统</title>
<jsp:include page="/pages/plugins/import_file.jsp"/>
<script type="text/javascript" src="js/pages/back/news/news_list.js"></script>
</head>
<body>
<div class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="main.html" target="_top">首页</a></li>
<li><a href="#">公告列表</a></li>
</ul>
</div>
<div class="rightinfo">
<div class="tools">
<ul class="toolbar">
<c:if test="${allActions['12'] != null}">
<li class="click" id="liButAdd"><span><img src="images/t01.png" /></span>添加</li>
</c:if>
<c:if test="${allActions['13'] != null}">
<li class="click" id="liButEdit"><span><img src="images/t02.png" /></span>修改</li>
</c:if>
<c:if test="${allActions['14'] != null}">
<li class="click" id="liButRm"><span><img src="images/t03.png" /></span>删除</li>
</c:if>
</ul>
</div>
<jsp:include page="/pages/plugins/split_page_plugin_search.jsp"/>
<table class="tablelist">
<thead>
<tr>
<th><input id="selAll" name="selAll" type="checkbox"/></th>
<th>编号</th>
<th>标题</th>
<th>公告分类</th>
<th>发布时间</th>
<th>是否查看</th>
</tr>
</thead>
<tbody>
<c:if test="${allNewses != null}">
<c:forEach items="${allNewses}" var="news">
<tr>
<td><input id="nid" name="nid" type="checkbox" value="${news.nid}" /></td>
<td>${news.nid}</td>
<c:if test="${allActions['33'] != null}">
<td><a href="<%=basePath%>/${allActions['33'].url}?news.nid=${news.nid}" target="rightFrame">
<c:if test="${unreadMap[news.nid]}">
<font color="red">[未读]</font>
</c:if>
${news.title}</a></td>
</c:if>
<c:if test="${allActions['33'] == null}">
<td><c:if test="${unreadMap[news.nid]}">
<font color="red">[未读]</font>
</c:if>${news.title}</td>
</c:if>
<td>${news.type == 0 ? "普通通知" : "重要通知"}</td>
<td>${news.pubdate}</td>
<td>${unreadMap[news.nid] ? "未读" : 已查看}</td>
</tr>
</c:forEach>
</c:if>
</tbody>
</table>
<jsp:include page="/pages/plugins/split_page_plugin_bar.jsp"/>
<div class="tip">
<div class="tiptop">
<span>提示信息</span><a></a>
</div>
<div class="tipinfo">
<span><img src="images/ticon.png" /></span>
<div class="tipright">
<p id="pMsg">是否确认对信息的修改 ?</p>
<cite>如果是请点击确定按钮 ,否则请点取消。</cite>
</div>
</div>
<div class="tipbtn">
<input id="butSure" type="button" class="sure" value="确定" />
<input id="butCancel" type="button" class="cancel" value="取消" />
</div>
</div>
</div>
</body>
</html>4 显示效果

四 控制层实现
1 页面属性定义
news.add.page=/pages/back/news/news_add.jsp
news.add.servlet=/pages/back/news/NewsServletBack/addPre
news.list.page=/pages/back/news/news_list.jsp
news.list.servlet=/pages/back/news/NewsServletBack/list
news.show.page=/pages/back/news/news_show.jsp
news.edit.page=/pages/back/news/news_edit.jsp2 控制层代码
package cn.mldn.crm.servlet.back;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.annotation.WebServlet;
import cn.mldn.crm.factory.ServiceFactory;
import cn.mldn.crm.vo.News;
import cn.mldn.util.BasepathUtil;
import cn.mldn.util.SplitUtil;
@SuppressWarnings("serial")
@WebServlet("/pages/back/news/NewsServletBack/*")
public class NewsServletBack extends AbstractCRMServlet {
private News news = new News();
public String editPre() {
if (super.isAction(13)) {
try {
super.request.setAttribute(
"news",
ServiceFactory.getINewsServiceBackInstance().editPre(
super.getMid(), this.news.getNid()));
} catch (Exception e) {
e.printStackTrace();
}
return "news.edit.page";
} else {
return "error.page";
}
}
public String rm() {
if (super.isAction(14)) {
String ids = super.getParameter("ids");
Set<Integer> set = new HashSet<Integer>();
String result[] = ids.split("\\|");
for (int x = 0; x < result.length; x++) {
set.add(Integer.parseInt(result[x]));
}
try {
if (ServiceFactory.getINewsServiceBackInstance().rm(
super.getMid(), set)) {
super.setMsgAndUrl("vo.rm.success", "news.list.servlet");
} else {
super.setMsgAndUrl("vo.rm.failure", "news.list.servlet");
}
} catch (Exception e) {
e.printStackTrace();
super.setMsgAndUrl("vo.rm.failure", "news.list.servlet");
}
return "forward.page";
} else {
return "error.page";
}
}
public String edit() {
if (super.isAction(13)) {
this.news.getMember().setMid(super.getMid());
try {
if (ServiceFactory.getINewsServiceBackInstance()
.edit(this.news)) {
super.setMsgAndUrl("vo.edit.success", "news.list.servlet");
} else {
super.setMsgAndUrl("vo.edit.failure", "news.list.servlet");
}
} catch (Exception e) {
e.printStackTrace();
super.setMsgAndUrl("vo.edit.failure", "news.list.servlet");
}
} else {
return "error.page";
}
return "forward.page";
}
public String addPre() {
if (super.isAction(12)) {
return "news.add.page";
} else {
return "error.page";
}
}
public String list() {
if (super.isAction(11)) {
SplitUtil su = super.handleSplitParam();
try {
Map<String, Object> map = ServiceFactory
.getINewsServiceBackInstance().listSplit(
super.getMid(), su.getColumn(),
su.getKeyWord(), su.getCurrentPage(),
su.getLineSize());
super.getSession().setAttribute("unread", 0);
super.request.setAttribute("allNewses", map.get("allNewses"));
super.request.setAttribute("unreadMap", map.get("unreadMap"));
super.request
.setAttribute("allRecorders", map.get("newsCount"));
request.setAttribute("url", BasepathUtil.getPath(super.request)
+ super.getPage("news.list.servlet"));
} catch (Exception e) {
e.printStackTrace();
}
return "news.list.page";
} else {
return "error.page";
}
}
public String show() {
if (super.isAction(33)) {
try {
super.request.setAttribute(
"news",
ServiceFactory.getINewsServiceBackInstance().show(
super.getMid(), this.news.getNid()));
} catch (Exception e) {
e.printStackTrace();
}
return "news.show.page";
} else {
return "error.page";
}
}
public String add() {
if (super.isAction(12)) {
this.news.getMember().setMid(super.getMid());
try {
if (ServiceFactory.getINewsServiceBackInstance().add(this.news)) {
super.setMsgAndUrl("vo.add.success", "news.add.servlet");
} else {
super.setMsgAndUrl("vo.add.failure", "news.add.servlet");
}
} catch (Exception e) {
e.printStackTrace();
super.setMsgAndUrl("vo.add.failure", "news.add.servlet");
}
} else {
return "error.page";
}
return "forward.page";
}
public News getNews() {
return news;
}
@Override
public String getMarkTitle() {
return "公告信息";
}
@Override
public String getUploadDir() {
return null;
}
@Override
public String getDefaultColumn() {
return "title";
}
@Override
public String getColumntData() {
return "公告标题:title|发布者:mid";
}
}五 业务层实现
package cn.mldn.crm.service.back.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import cn.mldn.crm.factory.DAOFactory;
import cn.mldn.crm.service.back.AbstractCRMServiceBack;
import cn.mldn.crm.service.back.INewsServiceBack;
import cn.mldn.crm.vo.MemberNews;
import cn.mldn.crm.vo.News;
public class NewsServiceBackImpl extends AbstractCRMServiceBack implements
INewsServiceBack {
@Override
public boolean add(News vo) throws Exception {
try {
if (super.isAction(vo.getMember().getMid(), 12)) {
vo.setPubdate(new Date()); // 发布日期设置为当前所在日期时间
return DAOFactory
.getINewsDAOInstance(super.dbc.getConnection())
.doCreate(vo);
}
return false;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
@Override
public Map<String, Object> listSplit(String mid, String column,
String keyWord, int currentPage, int lineSize) throws Exception {
try {
Map<String, Object> map = new HashMap<String, Object>();
if (super.isAction(mid, 11)) {
List<News> all = DAOFactory.getINewsDAOInstance(
this.dbc.getConnection()).findAllSplit(column, keyWord,
currentPage, lineSize);
if (all.size() > 0) {
Set<Integer> set = new HashSet<Integer>();
Iterator<News> iter = all.iterator();
while (iter.hasNext()) {
set.add(iter.next().getNid());
}
map.put("unreadMap",
DAOFactory.getIMemberNewsDAOInstance(
super.dbc.getConnection()).findAllNotId(
mid, set));
}
map.put("allNewses", all);
map.put("newsCount",
DAOFactory
.getINewsDAOInstance(this.dbc.getConnection())
.getAllCount(column, keyWord));
}
return map;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
@Override
public News show(String mid, int nid) throws Exception {
try {
if (super.isAction(mid, 33)) {
if (DAOFactory.getIMemberNewsDAOInstance(
super.dbc.getConnection()).getAllCountByMemberAndNews(
mid, nid) == 0) { // 没有读取过
MemberNews vo = new MemberNews();
vo.getMember().setMid(mid);
vo.getNews().setNid(nid);
vo.setRdate(new Date());
DAOFactory.getIMemberNewsDAOInstance(
super.dbc.getConnection()).doCreate(vo);
}
return DAOFactory
.getINewsDAOInstance(super.dbc.getConnection())
.findById(nid);
}
return null;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
@Override
public News editPre(String mid, int nid) throws Exception {
try {
if (super.isAction(mid, 13)) {
return DAOFactory
.getINewsDAOInstance(super.dbc.getConnection())
.findById(nid);
}
return null;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
@Override
public boolean edit(News vo) throws Exception {
try {
if (super.isAction(vo.getMember().getMid(), 13)) {
return DAOFactory
.getINewsDAOInstance(super.dbc.getConnection())
.doUpdate(vo);
}
return false;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
@Override
public boolean rm(String mid, Set<Integer> ids) throws Exception {
try {
if (ids.size() == 0) {
return false;
}
if (super.isAction(mid, 14)) {
return DAOFactory
.getINewsDAOInstance(super.dbc.getConnection())
.doRemove(ids);
}
return false;
} catch (Exception e) {
throw e;
} finally {
this.dbc.close();
}
}
}六 数据层实现
根据各业务层的的逻辑,实现自己的数据层实现。
版权声明:本文为chengqiuming原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。